CSSLint / csslint

Automated linting of Cascading Stylesheets
http://csslint.net
Other
4.76k stars 484 forks source link

writeSync can throw EAGAIN, but csslint doesn't handle it #765

Open cpitclaudel opened 4 years ago

cpitclaudel commented 4 years ago

Hi there,

I'm a maintainer of Flycheck, a linter UI for Emacs. I'm forwarding a bug report that we think is due to csslint. The report is at https://github.com/flycheck/flycheck/issues/1481. In brief, Emacs starts css lint as a subprocess connected to a pipe. csslint uses writeSync to write its errors out, and in files with many errors this generates more than 64kB (the size of the pipe) of output. At that point node raises an EAGAIN signal, which csslint doesn't catch:

  return binding.writeString(fd, buffer, offset, length, position);
                 ^

Error: EAGAIN: resource temporarily unavailable, write
    at Object.fs.writeSync (fs.js:741:18)
    at Object.print (/home/me/.config/yarn/global/node_modules/csslint/dist/cli.js:421:12)
    at processFiles (/home/me/.config/yarn/global/node_modules/csslint/dist/cli.js:272:25)
    at cli (/home/me/.config/yarn/global/node_modules/csslint/dist/cli.js:401:14)
    at Object.<anonymous> (/home/me/.config/yarn/global/node_modules/csslint/dist/cli.js:417:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

We've had the same issue in the past with other linters, though with stdin instead of stdout or stderr. We think it's an issue in nodejs (see https://github.com/nodejs/node/issues/4697), due to the fact that stdin and stdout are synchronous on Windows. In any case, when trying to write a large amount of output to stdout on Windows (more than the pipe buffer's size), writeSync can throw EAGAIN, and csslint doesn't catch this error.

Other projects have had the same issue and fixed it in various ways, e.g. eslint (https://github.com/eslint/eslint/issues/12212, https://github.com/eslint/eslint/pull/12230/) and mocha (https://github.com/JetBrains/mocha-intellij/issues/2, https://github.com/JetBrains/mocha-intellij/commit/fe9aee647cf6ff4729955efd2c2a2138e032310a). The fix is likely to not use fs.writeSync.

Take all this with a grain of salt, because I personally don't use Windows, nor nodejs :) But I do use csslint, and it works great for me ;)