0

I was looking at this thread Secure random token in Node.js and tried to make a function:

var crypto = require('crypto');
function token() { // create a secure token
    var token;
    crypto.randomBytes(48, function(ex, buf) {
        token = buf.toString('hex');
    });
    return token;
}
// more code...
var token = token();

It crashes:

  Error: read ECONNRESET
      at exports._errnoException (util.js:746:11)
      at TCP.onread (net.js:559:26)

Any reasons to why?

"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.

Community
  • 1
  • 1
basickarl
  • 37,187
  • 64
  • 214
  • 335
  • There's nothing in the code that you've shown here that makes any TCP or HTTP requests. Are you using `net` anywhere in your code? – Mike Lawson May 25 '15 at 02:49
  • @MikeLawson Ah! I'm sorry, as I don't know where this could originate. I'm using passport-local, a POST request was sent to my node-js server. A router then routed it to a new LocalStrategy and this function resides in the strategy. – basickarl May 25 '15 at 02:50
  • 1
    This sounds a lot like it's happening during your POST request where the server you're running is throwing an exception and closing the stream in the middle of processing. I'd look into that and see where that leads you. – Mike Lawson May 25 '15 at 02:55
  • @MikeLawson Sounds like a good plan, thanks. – basickarl May 25 '15 at 02:55
  • @MikeLawson I did trace the error to that function, so I'm guessing it's throwing an exception which I'm not catching. – basickarl May 25 '15 at 02:57

0 Answers0