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

SSL error #1903

Closed
neuroscr opened this issue Nov 14, 2015 · 11 comments
Closed

SSL error #1903

neuroscr opened this issue Nov 14, 2015 · 11 comments

Comments

@neuroscr
Copy link

Request version 2.64.0
Node: v4.0.0

Most HTTPS requests work but there's some type of SSL or network error that's causing me grief: TLSSocket can cause a connection error before socket._httpMessage is set. So connectionErrorHandler has an uncaught exception:

request/request.js:80
socket._httpMessage.emit('error', error)
^
TypeError: Cannot read property 'emit' of null
at TLSSocket.connectionErrorHandler (node_modules/request/request.js:80:24)
at TLSSocket.g (events.js:260:16)
at emitOne (events.js:82:20)
at TLSSocket.emit (events.js:169:7)
at emitErrorNT (net.js:1250:8)
at doNTCallback2 (node.js:429:9)

at process._tickCallback (node.js:343:17)

at Request.onRequestResponse (node_modules/request/request.js:885:25)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:415:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
at TLSSocket.socketOnData (_http_client.js:305:20)
at emitOne (events.js:77:13)
at TLSSocket.emit (events.js:169:7)

at Request.start (node_modules/request/request.js:834:12)
at Request.end (node_modules/request/request.js:1394:10)
at end (node_modules/request/request.js:564:14)
at Immediate._onImmediate (node_modules/request/request.js:578:7)
at processImmediate [as _immediateCallback] (timers.js:371:17)
@eugirdor
Copy link

I just encountered this same issue on request 2.65.0/node 5.1.1

eugirdor added a commit to eugirdor/request that referenced this issue Jan 28, 2016
@IvanMMM
Copy link

IvanMMM commented Mar 17, 2016

Same for me.
request v2.69.0
node v4.4.0

@davidrissato
Copy link

I had a similar issue here today, but unrelated to SSL:

TypeError: Cannot read property 'emit' of null
at Socket.connectionErrorHandler (.../node_modules/request/request.js:82:24)
at Socket.g (events.js:273:16)
at emitOne (events.js:95:20)
at Socket.emit (events.js:182:7)
at emitErrorNT (net.js:1258:8)
at _combinedTickCallback (node.js:383:13)
at process._tickCallback (node.js:407:11)

request v2.69.0 / Node v5.9.0.

@jmyersmsft
Copy link

I am also seeing this, though I think for me it's happening on sockets that have been returned to the pool, possibly only after a redirect.

request v2.72.0 / node v6.2.0

@brphelps
Copy link

brphelps commented Jun 1, 2016

I've been observing this happening in my CI's as well, in the context of NPM failing :). Is there anything I can do to help address the issue?

90258 verbose stack TypeError: Cannot read property 'emit' of null
90258 verbose stack at TLSSocket.connectionErrorHandler (C:\Users\svccbld\AppData\Roaming\npm\node_modules\npm\node_modules\request\request.js:82:24)
90258 verbose stack at TLSSocket.g (events.js:260:16)
90258 verbose stack at emitOne (events.js:82:20)
90258 verbose stack at TLSSocket.emit (events.js:169:7)
90258 verbose stack at emitErrorNT (net.js:1253:8)
90258 verbose stack at nextTickCallbackWith2Args (node.js:442:9)
90258 verbose stack at process._tickCallback (node.js:356:17)
90259 verbose cwd E:\A_work\3\s\Product\Source\Web

@djphoenix
Copy link

Same issue
nodejs v6.2.1, request v2.72.0

@zarenner
Copy link
Contributor

zarenner commented Jun 3, 2016

Trying to create a simple repro - reuse of sockets and redirects to different hosts seem to be a factor.

@zarenner
Copy link
Contributor

zarenner commented Jun 3, 2016

Here's a simple repro:
Client:

var http = require('http')
var request = require('request')

var options = {
    // Redirects to http://localhost2:3000/node-requests-test/hello
    url: "http://localhost1:3000/node-requests-test/redirect",
    forever: true
}

// Doesn't repro if keepAlive: false
options.agent = new http.Agent({ keepAlive: true });
request(options)

// Wait...
setTimeout(_ => {}, 10000000)

Output (my own changes to request.js):

DEBUG: onRequestResponse: Registered connectionErrorHandler for localhost1
DEBUG: Redirect to http://localhost2:3000/node-requests-test/hello
DEBUG: onRequestResponse: Registered connectionErrorHandler for localhost2
DEBUG: Removed listener for localhost2
DEBUG: Removed listener for localhost2

Server is an IIS ASP.NET server that redirects from /node-requests-test/redirect to /node-requests-test/hello. Changing the server's connection timeout directly corresponds with when the client exception occurs, and only repros if keep-alive is enabled on the server.

Looks like the error handler listener for the redirect isn't getting removed.

@zarenner
Copy link
Contributor

@mscdex and @mikeal, I know it was forever ago but are you able to explain the purpose of connectionErrorHandler? You added it in /pull/293.
Was it just working around an old bug in core or is it still necessary?

Code today:

// Function for properly handling a connection error
function connectionErrorHandler(error) {
  var socket = this
  if (socket.res) {
    if (socket.res.request) {
      socket.res.request.emit('error', error)
    } else {
      socket.res.emit('error', error)
    }
  } else {
    socket._httpMessage.emit('error', error)
  }
}

I can't find any record of what socket.res is, and as far as I can tell in _http_client.js in core, socketErrorListener already emits error on the ClientRequest (_httpMessage) so I don't see why we'd need to here.

@mscdex
Copy link
Contributor

mscdex commented Jun 10, 2016

@zarenner I don't remember, that was 4 years ago :-). However, the http parser error bubbling fix has existed now in node for quite a long time. Because of that fact, the changes in that other PR shouldn't even be necessary anymore AFAIK.

@zarenner
Copy link
Contributor

zarenner commented Jun 10, 2016

@mscdex Thanks, assumed that would be the case.
I think I'll open a PR to remove your original changes then, and maybe someone with more recent familiarity can chime in.

On another note, I think there might be additional potential problems with some of the listeners on the Request getting added multiple times on redirect. edit: Looks like #2028 addresses those issues.

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

9 participants