http: fix keylog listener setup on existing agent sockets · nodejs/node@6c3516f · GitHub
Skip to content

Commit 6c3516f

Browse files
shani-singh1aduh95
authored andcommitted
http: fix keylog listener setup on existing agent sockets
`maybeEnableKeylog()` runs as the agent's `'newListener'` handler and attaches the agent's keylog handler to the sockets the agent already owns. `agent.sockets` maps a name to an array of sockets, but the loop treated those arrays as sockets and called `.on()` on them. Adding a `'keylog'` listener to an agent that already owned a socket therefore threw `TypeError: sockets[i].on is not a function` out of `agent.on('keylog', ...)`. Since the throw happened inside the `'newListener'` handler it propagated before the listener was stored, so the caller got an exception and no listener. Sockets parked in `agent.freeSockets` were never visited at all. Walk both maps the way `Agent.prototype.destroy()` does. Signed-off-by: Shani Singh <teamdeveloperworld@gmail.com> PR-URL: #65066 Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent 613be79 commit 6c3516f

2 files changed

Lines changed: 82 additions & 4 deletions

File tree

lib/_http_agent.js

Lines changed: 11 additions & 4 deletions
Lines changed: 71 additions & 0 deletions

0 commit comments

Comments
 (0)