creationix/http-parser-js

timeout event listener registration error

Closed this issue · 2 comments

Hi all, I've been working on a tool to identify instances of events registered to the wrong object in uses of some JavaScript event-driven APIs, as part of a research project.
The tool flagged line 155 in tests/parallel/test-http-set-timeout-server.js, on the registration of the “timeout” event.

The reason I believe this is indicative of an error is as follows (from looking at the nodejs http API documentation:
The req variable, as the first argument to the callback of createServer (on line 154), is an object of type http.IncomingMessage. However, the “timeout” event is not emitted on http.IncomingMessage.

Since the name “req” implies that this variable should be a request, my guess is that the author of this code thought that req was an object of type http.ClientRequest, where “timeout” is actually emitted.
For example, in another location in the testing code there is a registration of a listener for “timeout” on another variable called req, but this one is actually an http.ClientRequest, since it is the result of a call to http.request.

Thanks!

Thanks!

The tests here are just a copy of the ones in Node proper, and they're also registering this event, however, the test is specifically testing that a timeout event is not emitted, so I think everything's fine, even if it's an unnecessary assertion.

Ah ok that makes sense, thanks for looking into it and letting me know! :)