end event listener registration error
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 74 in test/bench.js, on the registration of the "end" event.
The reason I believe this is an error as follows (from looking at the nodejs http API documentation, particularly https://nodejs.org/api/http.html#http_http_get_options_callback): The return of https.get(...) is an http.ClientRequest object, and res, as the argument to the callback handleResponse passed to get, is an http.IncomingMessage. “end” is an event on http.IncomingMessage, and not on http.ClientRequest (you even have a registration of a listener for “end” on res, in the body of the handleResponse callback).
A common event indicative of an error to listen to on http.ClientRequest is “timeout”, so my guess is that maybe your registration on line 74 should be for “timeout” instead of “end”.
What about the error event shown in the example snippet at https://nodejs.org/api/http.html#http_http_get_options_callback? A common EventEmitter feature, it is barely documented as part of the ClientRequest API.
Also, timeout listeners receive no arguments.
Good point, that would make sense! Plus the listener argument is even named err.