()
| 9650 | } |
| 9651 | socket.on("close", onClose); |
| 9652 | function onTimeout() { |
| 9653 | const listenerCount = socket.listeners("timeout").length; |
| 9654 | const timeout = getSocketTimeout(socket); |
| 9655 | const req = socket._httpMessage; |
| 9656 | const reqTimeoutListenerCount = req && req.listeners("timeout").length || 0; |
| 9657 | debug5( |
| 9658 | "%s(requests: %s, finished: %s) timeout after %sms, listeners %s, defaultTimeoutListenerCount %s, hasHttpRequest %s, HttpRequest timeoutListenerCount %s", |
| 9659 | socket[SOCKET_NAME], |
| 9660 | socket[SOCKET_REQUEST_COUNT], |
| 9661 | socket[SOCKET_REQUEST_FINISHED_COUNT], |
| 9662 | timeout, |
| 9663 | listenerCount, |
| 9664 | defaultTimeoutListenerCount, |
| 9665 | !!req, |
| 9666 | reqTimeoutListenerCount |
| 9667 | ); |
| 9668 | if (debug5.enabled) { |
| 9669 | debug5("timeout listeners: %s", socket.listeners("timeout").map((f4) => f4.name).join(", ")); |
| 9670 | } |
| 9671 | agent.timeoutSocketCount++; |
| 9672 | const name = agent.getName(options); |
| 9673 | if (agent.freeSockets[name] && agent.freeSockets[name].indexOf(socket) !== -1) { |
| 9674 | socket.destroy(); |
| 9675 | agent.removeSocket(socket, options); |
| 9676 | debug5("%s is free, destroy quietly", socket[SOCKET_NAME]); |
| 9677 | } else { |
| 9678 | if (reqTimeoutListenerCount === 0) { |
| 9679 | const error = new Error("Socket timeout"); |
| 9680 | error.code = "ERR_SOCKET_TIMEOUT"; |
| 9681 | error.timeout = timeout; |
| 9682 | socket.destroy(error); |
| 9683 | agent.removeSocket(socket, options); |
| 9684 | debug5("%s destroy with timeout error", socket[SOCKET_NAME]); |
| 9685 | } |
| 9686 | } |
| 9687 | } |
| 9688 | socket.on("timeout", onTimeout); |
| 9689 | function onError(err) { |
| 9690 | const listenerCount = socket.listeners("error").length; |
nothing calls this directly
no test coverage detected
searching dependent graphs…