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

kIncomingMessage undefined for socket.server #19231

Closed
leiyangyou opened this issue Mar 8, 2018 · 5 comments
Closed

kIncomingMessage undefined for socket.server #19231

leiyangyou opened this issue Mar 8, 2018 · 5 comments
Labels
confirmed-bug Issues with confirmed bugs. http Issues or PRs related to the http subsystem.

Comments

@leiyangyou
Copy link

leiyangyou commented Mar 8, 2018

after upgrading to node 9.7 some existing code started crashing when calling socket.emit('data', data)

the socket was created by net/Server, and later added to an httpServer through httpServer.emit('connection', socket)

I understand that the usage may be a bit hacky, but this was how some third party library implemented a hybrid server (one that takes both tcp & ws connections)

@leiyangyou leiyangyou changed the title this crashes some existing code, is this intentional? kIncomingMessage undefined for socket.server Mar 8, 2018
@leiyangyou leiyangyou reopened this Mar 8, 2018
@gireeshpunathil
Copy link
Member

do you have the full code to reproduce?

@leiyangyou
Copy link
Author

leiyangyou commented Apr 9, 2018

Hi, please refer to

https://github.com/NetEase/pomelo/blob/5f7bec1c9be5fa2f88a366b15085cf64d4e786d7/lib/connectors/hybrid/wsprocessor.js#L30

the socket was initially created by a net/Server & bound to the server, which does not have a kIncomingMessage defined

Processor.prototype.add = function(socket, data) {
  if(this.state !== ST_STARTED) {
    return;
  }
  this.httpServer.emit('connection', socket);
  if(typeof socket.ondata === 'function') {
    // compatible with stream2
    socket.ondata(data, 0, data.length);
  } else {
    // compatible with old stream
    socket.emit('data', data);
  }
};

my current hacky fix involves doing this

Processor.prototype.add = function(socket, data) {
  if(this.state !== ST_STARTED) {
    return;
  }
  socket.server = this.httpServer
  this.httpServer.emit('connection', socket);
  if(typeof socket.ondata === 'function') {
    // compatible with stream2
    socket.ondata(data, 0, data.length);
  } else {
    // compatible with old stream
    socket.emit('data', data);
  }
};

@gireeshpunathil
Copy link
Member

/cc @nodejs/http - is the hybrid use case (mixing net' socket to be fused into the http server and the problems arises there on) supported?

@leiyangyou
Copy link
Author

leiyangyou commented Apr 9, 2018 via email

@apapirovski
Copy link
Member

@gireeshpunathil I don't think it's meant to be supported in the way that it's used here but it did work until now... We should probably resolve.

@apapirovski apapirovski added confirmed-bug Issues with confirmed bugs. http Issues or PRs related to the http subsystem. labels Apr 11, 2018
jasnell pushed a commit that referenced this issue Apr 17, 2018
The current check for socket.server[kIncomingMessage] does not
account for the possibility of a socket.server that doesn't
have that property defined. Fix it.

PR-URL: #20029
Fixes: #19231
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
trivikr pushed a commit to trivikr/node that referenced this issue Sep 15, 2018
The current check for socket.server[kIncomingMessage] does not
account for the possibility of a socket.server that doesn't
have that property defined. Fix it.

PR-URL: nodejs#20029
Fixes: nodejs#19231
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
MylesBorins pushed a commit that referenced this issue Oct 31, 2018
The current check for socket.server[kIncomingMessage] does not
account for the possibility of a socket.server that doesn't
have that property defined. Fix it.

Backport-PR-URL: #22880
PR-URL: #20029
Fixes: #19231
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants