uploadcare / uploadcare-node

Node module for uploadcare.com
MIT License
37 stars 21 forks source link

Cannot read property 'setEncoding' of undefined #18

Closed sasneutrino closed 6 years ago

sasneutrino commented 7 years ago

This what I get sometimes, not always, I don't understand why.

I20170806-18:10:35.970(2)? { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
W20170806-18:10:35.972(2)? (STDERR) /Users/lol/Dropbox/Apps/cw.com/cw/node_modules/uploadcare/lib/main.js:22
W20170806-18:10:35.974(2)? (STDERR)     res.setEncoding('utf8');
W20170806-18:10:35.975(2)? (STDERR)        ^
W20170806-18:10:35.975(2)? (STDERR) 
W20170806-18:10:35.975(2)? (STDERR) TypeError: Cannot read property 'setEncoding' of undefined
W20170806-18:10:35.976(2)? (STDERR)     at setup_response_handler (/Users/lol/Dropbox/Apps/cw.com/cw/node_modules/uploadcare/lib/main.js:22:8)
W20170806-18:10:35.977(2)? (STDERR)     at ClientRequest.<anonymous> (/Users/lol/Dropbox/Apps/cw.com/cw/node_modules/uploadcare/lib/main.js:114:13)
W20170806-18:10:35.977(2)? (STDERR)     at emitOne (events.js:77:13)
W20170806-18:10:35.977(2)? (STDERR)     at ClientRequest.emit (events.js:169:7)
W20170806-18:10:35.978(2)? (STDERR)     at TLSSocket.socketErrorListener (_http_client.js:269:9)
W20170806-18:10:35.978(2)? (STDERR)     at emitOne (events.js:77:13)
W20170806-18:10:35.979(2)? (STDERR)     at TLSSocket.emit (events.js:169:7)
W20170806-18:10:35.979(2)? (STDERR)     at emitErrorNT (net.js:1272:8)
W20170806-18:10:35.980(2)? (STDERR)     at nextTickCallbackWith2Args (node.js:511:9)
W20170806-18:10:35.980(2)? (STDERR)     at process._tickCallback (node.js:425:17)
rsp commented 6 years ago

@sasneutrino Looking at the source code there is a place in _submit function where it checks for error and if there is error it is logged - which is probably what you see as the line starting with { [Error: read ECONNRESET] ... - but even if there is an error it still calls another function setup_response_handler - see:

The setup_response_handler doesn't check if the res is undefined (which it will be if there was an error in _submit above. See:

It seems that this is a problem.

@RexMorgan is this project alive? This issue has been open for half a year.

RexMorgan commented 6 years ago

@rsp Thanks for doing the deep dive on this and figuring out what the issue was. I had glanced over the code awhile back trying to see why this was happening and didn't notice this.

This is fixed and published to npm in version 0.4.5.

PRs are welcome if you find other things that could use improvement. I'm not actively working on this or even working in node at the moment. I work on this when I get the time.