Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

"Unhandled stream error in pipe" from Node.js

"Unhandled stream error in pipe" from Node.js

Problem

My app: Node.js, Express, some middleware including connect-assets and express.static.

All running on local machine (OSX, Node 0.8) in development mode (thus express.static).

Probably important details: I recently made the whole app work through HTTPS (with redirect from HTTP when necessary) and while developing I use self-signe certificate (enabled in my browser, of course).

Now, the app is often failing wit stack traces like that:

(1)

stream.js:81
  throw er; // Unhandled stream error in pipe.
        ^
Error: write EPIPE
    at errnoException (net.js:769:11)
    at Object.afterWrite (net.js:593:19)

(2)

stream.js:81
  throw er; // Unhandled stream error in pipe.
        ^
Error: socket hang up
    at SecurePair.error (tls.js:948:15)
    at EncryptedStream.CryptoStream._done (tls.js:432:17)
    at EncryptedStream.CryptoStream._pull (tls.js:577:12)
    at SecurePair.cycle (tls.js:866:20)
    at EncryptedStream.CryptoStream.end (tls.js:405:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

(3)

stream.js:81
  throw er; // Unhandled stream error in pipe.
        ^
Error: socket hang up
    at createHangUpError (http.js:1264:15)
    at CleartextStream.socketCloseListener (http.js:1315:23)
    at CleartextStream.EventEmitter.emit (events.js:126:20)
    at SecurePair.destroy (tls.js:938:22)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Important: this happens often but not every time, so I assume this not to be a bug in my code.

I found this can be due to express.static and open files limit so I ran ulimit -n 10000 - with no effect, unfortunately.

Any ideas? This starts to be extremely frustrating.

Problem courtesy of: Guard

Solution

OK, looks like I found the answer (at least I found a similar problem mentioned, tried their fix and it stopped falling):

the express.static middleware must be the last in the chain

Solution courtesy of: Guard

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

"Unhandled stream error in pipe" from Node.js

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×