Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: stream.push() after EOF #16

Closed
jotto opened this issue Jul 6, 2018 · 3 comments
Closed

Error: stream.push() after EOF #16

jotto opened this issue Jul 6, 2018 · 3 comments

Comments

@jotto
Copy link
Contributor

jotto commented Jul 6, 2018

Explanation

I'm intermittently getting these stream.push errors on an HTTP server, which seem to terminate the Node process, even with a process.on("unhandledRejection"). I assume the error is happening because the HTTP client is disconnecting before the stream finishes, but why can't I seem to capture these errors and/or prevent Node from terminating?

Possible solution?

Could it be as simple as adding try/catch around the .push call in readStream?

this.push(this._object.slice(this._offset, this._offset + size));

Error message/stack

Note, the line numbers in this stack trace are a little off because I'm using the forked code from #14

Error: stream.push() after EOF
    at readableAddChunk (_stream_readable.js:240:30)
    at ReadStream.Readable.push (_stream_readable.js:208:10)
    at ReadStream._push (/app/node_modules/streaming-cache/lib/readStream.js:44:14)
    at ReadStream.setBuffer (/app/node_modules/streaming-cache/lib/readStream.js:19:10)
    at EventEmitter.<anonymous> (/app/node_modules/streaming-cache/index.js:105:16)
    at emitOne (events.js:116:13)
    at EventEmitter.emit (events.js:211:7)
    at Duplex.<anonymous> (/app/node_modules/streaming-cache/index.js:204:28)
    at emitNone (events.js:111:20)
    at Duplex.emit (events.js:208:7)
    at finishMaybe (_stream_writable.js:614:14)
    at endWritable (_stream_writable.js:622:3)
    at Duplex.Writable.end (_stream_writable.js:573:5)
    at ReadStream.onend (_stream_readable.js:595:10)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at ReadStream.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Code looks like:

app.get('/', (req, res) => {
  const streamingCached = streamingCache.get("some-cache-key");

  if (streamingCached) {
    return streamingCached
      .pipe(res)
      .on("error", console.error)
  }
})
@jotto
Copy link
Contributor Author

jotto commented Jul 6, 2018

I deployed the try/catch and it seems to have addressed the problem: https://github.com/jotto/streaming-cache/commit/aa9f63c27889d6cbcb62f46d627fc11de110bb6e

@LaurentZuijdwijk
Copy link
Owner

@jotto, thanks for your work on this and sorry for the late reply.
It seems like this issue is similar jeffbski/redis-rstream#4 and their solution was to use a try/catch. There might be a small performance price to pay, but it shouldn't be too bad.

I would suggest using 'uncaughtException' in your code. 'unhandledRejection' is only used for promises.

The following might help as well. Errors are not automatically forwarded in a stream.

  if (streamingCached) {
    streamingCached    
     .on("error", console.error)
     return streamingCached
      .pipe(res)
      .on("error", console.error)
  }

@LaurentZuijdwijk
Copy link
Owner

Will close this issue. A new version has been pushed to NPM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants