The recently added Connection#wrapWithTls method does not behave correctly if the connection timeout fires during the TLS negotiation.
When the connect timeout fires, we dispatch a ConnectionError to the connect event and move the internal state over to the FINAL state. Because we haven't fully connected yet, the network socket does not get cleaned up when moving to the FINAL state.
When the connection timeout fires between the call to connect and before wrapWithTls returns, we never clean up the socket correctly, because wrapWithTls doesn't return an error if the connection timeout fires.
I think this can be fixed by making wrapWithTls take the signal passed to connectOnPort, and handle it correctly (i.e. call signal.throwIfError at the beginning of the function, and set the correct event handlers to reject the promise if the signal is aborted).
The recently added
Connection#wrapWithTlsmethod does not behave correctly if the connection timeout fires during the TLS negotiation.When the connect timeout fires, we dispatch a
ConnectionErrorto theconnectevent and move the internal state over to theFINALstate. Because we haven't fully connected yet, the network socket does not get cleaned up when moving to theFINALstate.When the connection timeout fires between the call to
connectand beforewrapWithTlsreturns, we never clean up the socket correctly, becausewrapWithTlsdoesn't return an error if the connection timeout fires.I think this can be fixed by making
wrapWithTlstake thesignalpassed toconnectOnPort, and handle it correctly (i.e. callsignal.throwIfErrorat the beginning of the function, and set the correct event handlers to reject the promise if the signal is aborted).