question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

STDIN breaks after refreshing piped executables

See original GitHub issue
  • nodemon -v: ^1.19.4
  • node -v: v13.3.0
  • Operating system/terminal environment: Windows/Git Bash
  • Using Docker? What image:
  • Command you ran: nodemon -e js --exec “node …\external\secret.js | node server.js”

Expected behaviour

Run consistently, at least always give me an error.

Actual behaviour

Somehow, I get trapped getting errors if my code produces an error in a refresh. Sometimes, not consistent with any other events that I can tell, I keep getting the error below every time I try and refresh. I can open a new shell terminal, I can close/reopen all shell terminals on the system, but every time I try and run the command it spits out this error. If I wait for another 5-10min, it seems to just go away on its own.

I’m getting an error from node’s built-in fs module: internal/fs/utils.js:227 throw err; Error: EOF: end of file, read errno: -4095, syscall: ‘read’, code: ‘EOF’

Steps to reproduce

Run a express server that blocks on being initialized from data from stdin, then add a throw at the beginning, save/refresh through nodemon, remove the throw and attempt to run again. Like I said this seems to be entirely unpredictable; so sometimes I’ll have to add/remove the throw a couple times or restart my shell.

// Source file
const objectToWrite = { somedata:'someval' }
process.stdout.write(JSON.stringify(objectToWrite));
process.stdout.end('\n');
// I've messed around with various STDIO implementations
// and it doesn't seem to have any affect the error.

// Receiving file
const fs = require('fs')
let envTmp = fs.readFileSync(0).toString();
// breaks on fs utils here ^
	envTmp = JSON.parse(envTmp);

Dump Text

[nodemon] 1.19.4 [nodemon] to restart at any time, enter rs [nodemon] watching dir(s): . [nodemon] watching extensions: js

node: v13.3.0 nodemon: 1.19.4 command: C:\Program Files\nodejs\node.exe bin\nodemon.js -e js --exec node …\secret.js | node server.js --dump OS: win32 x64

{
  run: false,
  required: false,
  timeout: 1000,
  options: {
    exec: 'node ..\\secret.js | node server.js',
    dump: true,
    ignore: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**',
      re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/
    ],
    watch: [ '*.*', re: /.*\..*/ ],
    ignoreRoot: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**'
    ],
    restartable: 'rs',
    colours: true,
    execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' },
    stdin: true,
    runOnChangeOnly: false,
    verbose: false,
    signal: 'SIGUSR2',
    stdout: true,
    watchOptions: {},
    execOptions: {
      script: null,
      exec: 'node ..\\secret.js | node server.js',
      args: [],
      scriptPosition: null,
      nodeArgs: undefined,
      execArgs: [],
      ext: 'js',
      env: {}
    },
    monitor: [
      '*.*',
      '!**/.git/**',
      '!**/.nyc_output/**',
      '!**/.sass-cache/**',
      '!**/bower_components/**',
      '!**/coverage/**',
      '!**/node_modules/**'
    ]
  },
  load: [Function (anonymous)],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  watchInterval: null,
  signal: 'SIGUSR2',
  command: {
    raw: {
      executable: 'node ..\\secret.js | node server.js',
      args: []
    },
    string: 'node ..\\secret.js | node server.js'
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
josh-hemphillcommented, Mar 26, 2020

I just refactored my code to wrap the whole thing in a .then() to use the normal process.stdin and now it doesn’t seem to have any issues.

Does nodemon try and detect if stdin is being used? Maybe it just missed fs.readFileSync(0)?

1reaction
remycommented, Feb 17, 2020

Can you provide a pared down code sample to run? Otherwise I can’t reproduce.

Read more comments on GitHub >

github_iconTop Results From Across the Web

podman exec -i truncates the STDIN input · Issue #5046 - GitHub
I tried to get Ansible working with pipelining. Pipelining makes use of STDIN. The following command works fine with 1.8.0-dev :.
Read more >
python - How do I read from stdin? - Stack Overflow
It works with pipe and prompt on Windows (not tested on Linux yet). When prompting, two line breaks indicate end of input. def...
Read more >
subprocess — Subprocess management — Python 3.11.1 ...
Special value that can be used as the stdin, stdout or stderr argument to Popen and indicates that a pipe to the standard...
Read more >
Piping data to a process's stdin without causing EOF afterward
This almost works. The problem is that the echo command that is feeding the process's stdin hits EOF once it's done echoing my...
Read more >
DDD use - GNU.org
break location is a typed command at the (gdb) prompt; the metasyntactic variable location would be replaced by the actual location. _ is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found