"Unhandled stream error in pipe" from Node.js - node.js

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.

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

Related

Nodejs server stop with error

My server stops with this error how can i solve it? Or what it is?
events.js:182
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:1024:11)
at TCP.onread (net.js:610:25)
Thanks for answers
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one or more application protocol errors. You could look at the API server logs to see if it complains about something.
To know more about ECONNRESET, see this answer.
The message Unhandled 'error' event is suggesting that you are not listening for the error event in your code.
You can catch errors like these by catching the error event like the following
connection.on("error", function(err){ // handle "error" event so nodejs will not crash
console.log(err);
});

NodeJs server crashing randomly: events.js:72 EIO

I'm running a NodeJs server on linux and after several hours up it crashes:
events.js:72
throw er; // Unhandled 'error' event
^
Error: write EIO
at errnoException (net.js:901:11)
at Object.afterWrite (net.js:718:19)
Can anyone help me please??
Why downvoting?
I actually managed to fix it. This helped a lot: How to make a node.js application run permanently?
The problem was that the process was trying to write into a closed terminal.

Where is child_process.js?

I am trying to debug a problem with forever/nodejs, and I get this stacktrace in the error log:
chdir(): Permission denied
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn EACCES
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
This looks to me like I should be able to look at line 980 of a file named "child_process.js" to see where the error is thrown. However, I cannot locate such a file on the system even with "find". Am I missing it somehow, or is the stracktrace lying?
It's part of the node.js source. See https://github.com/joyent/node/blob/master/lib/child_process.js. I believe you can also step directly through core node code using node's built-in debugger, or a package such as node-inspector.

How to troubleshoot ECONNREFUSED error?

I'm trying to get the d3.js demo given here to work.
I'm following along the instructions in the README.md file. I get the npm install step to work, but the next step, node server, fails:
% node server
Master pid 16196
16197 listening. Go to: http://localhost:3030/
events.js:72
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
at RedisClient.on_error (/Users/yrstruly/tmp/derby-barchart/node_modules/redis/index.js:189:24)
at Socket.<anonymous> (/Users/yrstruly/tmp/derby-barchart/node_modules/redis/index.js:95:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
It looks like the code is expecting to have some process listening to port 6379, but the README says nothing about this.
I'm quite unfamiliar with most of the software used by this demo. In particular, I know very little about node.js, derby, and redis. Therefore, I'm following the steps in the README rather blindly. Any help with troubleshooting this error would be appreciated.

Node.js and Sphinx concurrent connection issue on Server

I have been using Sphinx Technology for site and implemented in php and Node.js. Using php and Sphinx, so far i didn't get any issues. But with Node.js and Sphinx, i got the following issues rapidly,
1. Error: Error: Connection is opening in OnConnect
at Socket.<anonymous> (/usr/local/lib/node_modules/limestone/limestone.js:217:26)
at Socket.emit (events.js:64:17)
at Object.afterConnect [as oncomplete] (net.js:614:10)
2. node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: write EPIPE
at errnoException (net.js:640:11)
at Object.afterWrite [as oncomplete] (net.js:478:18)
I have been using limestone node.js module as middleware between Node.js and Sphinx server. My assumption is that above error is occured due to the concurrent connection request to Sphinx. If so, then how to avoid the concurrent sphinx request.
Please suggest on the same.
you can try using sphinxql via one of mysql libraries available for sphinx.

Resources