node-cssjanus icon indicating copy to clipboard operation
node-cssjanus copied to clipboard

end event listener registration error

Open emarteca opened this issue 6 years ago • 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 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”.

emarteca avatar Dec 02 '19 18:12 emarteca

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.

ricordisamoa avatar Dec 05 '19 14:12 ricordisamoa

Good point, that would make sense! Plus the listener argument is even named err.

emarteca avatar Dec 05 '19 15:12 emarteca