redline
LowPerformancesync-io

Blocking file or process call

Blocking file or process call. readFileSync blocks the event loop. Every other request waits.

This is how the comment reads inline, under the flagged line.

Why it matters

Sync I/O in a server stops all concurrent work until the disk or child process returns.

What to do

Use the async version (fs/promises, execFile), or do it once at startup.

Examples

Flagged
const tpl = fs.readFileSync(path, 'utf8');
Better
const tpl = await fs.promises.readFile(path, 'utf8');

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript. Scope: Shipped code only. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

const a = fs.readFileSync(p);

Left alone

const a = await fs.promises.readFile(p);
scripts/gen.ts
const a = fs.readFileSync(p);

Research

Blocking file, process or HTTP calls in server or async code. One blocking call stalls every other request on the event loop.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "sync-io"
    ],
    "severity": {
      "sync-io": "medium"
    }
  }
}

Read the source or report a false positive.