Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JSON parse related SyntaxError sporadically during spawnServer #1463

Copy link
Copy link
@sam-perez

Description

@sam-perez
Issue body actions
Image

Affected line of code:

  return new Promise((resolve, reject) => {
    const interval = setInterval(() => {
      if (fs.existsSync(filepath)) {
        const connectionJSON = fs.readFileSync(filepath).toString("utf-8");
        resolve({
          serverPID: server.pid,
          connectionFilepath: filepath,
          connectionOptions: JSON.parse(connectionJSON) \\ <----- OFFENDING LINE OF CODE
        });

        clearTimeout(timeout);
        clearInterval(interval);
      } else if (server.exitCode) {
        reject(new Error("Failed to start parse server."));
        clearTimeout(timeout);
        clearInterval(interval);
      }
    }, 100);

I've been seeing this error pop up now and again. I was wondering, is there an actual race condition here between writing the file and reading the file? Is it possible that the file being written is only partially written, and if you read it at the wrong moment you will get this JSON parse error?

If so, then maybe the JSON parse error should be handled gracefully?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.