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

HTTP server adds .on override to sockets but not .appendListener #27199

Closed
Antonius-S opened this issue Apr 12, 2019 · 8 comments
Closed

HTTP server adds .on override to sockets but not .appendListener #27199

Antonius-S opened this issue Apr 12, 2019 · 8 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@Antonius-S
Copy link

  • Version: v10.15.1 but affects master branch, v12 and so on
  • Platform: W7
  • Subsystem: HTTP server

Here HTTP server adds a .on wrapper to a socket. But no other listener methods are wrapped so if we call socket.addListener() or socket.prependListener() we'll get other results than if we called socket.on().

'use strict';

const http = require('http');

const srv = http.createServer();
srv.on('connection', (socket) => {
	console.log(socket.on === socket.addListener);
});
@ZYSzys ZYSzys added the http Issues or PRs related to the http subsystem. label Apr 13, 2019
@SimonSchick
Copy link
Contributor

@Antonius-S
Copy link
Author

@SimonSchick this is probably really a proper way

@sam-github
Copy link
Contributor

This looks to be an oversight/bug in the API to me, @nodejs/http ?

@GrosSacASac
Copy link
Contributor

A future proof solution would be to iterate on all Event emitter methods, and do the assignement for each method name that is equal to on

@GrosSacASac
Copy link
Contributor

Off topic:
Why do this :

Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
Object.setPrototypeOf(ServerResponse, OutgoingMessage); // ???

@Antonius-S
Copy link
Author

Antonius-S commented Apr 17, 2019

A future proof solution would be to iterate on all Event emitter methods, and do the assignement for each method name that is equal to on

I don't think so. Mechanism of virtual functions is very nice in other languages but in JS it's a dirty and error-prone hack. Monkeypatching is acceptable for final objects but those in library are likely to be instantiated and extended. I'd vote for 'newlistener' listener

@GrosSacASac
Copy link
Contributor

Yes, sorry I didn't see the replies

@himself65
Copy link
Member

himself65 commented Apr 20, 2019

this bug caused by this code line

socket.on = socketOnWrap;

when I try

srv.on('connection', (socket) => {
	console.log(socket.on)
	console.log(socket.addListener)
})

logged

[Function: socketOnWrap]
[Function]

himself65 added a commit to himself65/node that referenced this issue May 2, 2019
targos pushed a commit that referenced this issue May 20, 2019
Fixes: #27199

PR-URL: #27325
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants