When calling Start() and then Stop() on the initiator with a connection that is failing or timing out, sending a SIGTERM prevents the program from exiting because of the call to Dial in handleConnection.
Reducing the SocketTimeout to a lower value mitigates this issue, since the call to Dial will exit early and then exit when checking on the stopChan in waitForReconnectInterval. However this is not a clean solution and prevents flexibility from consumers of the library to be able to stop the connect process immediately.
The reason why is that the handleConnection method is taking in a proxy.Dialer which doesn't contain a dialer.DialContext method required to cancel the connection mid-way with a cancellation signal.
As a solution, we can cast the proxy.Dialer to a proxy.ContextDialer and let the call to Stop() properly exit the connection process with the use of a context on handleConnection.
When calling
Start()
and thenStop()
on the initiator with a connection that is failing or timing out, sending a SIGTERM prevents the program from exiting because of the call to Dial inhandleConnection
.Reducing the
SocketTimeout
to a lower value mitigates this issue, since the call toDial
will exit early and then exit when checking on thestopChan
inwaitForReconnectInterval
. However this is not a clean solution and prevents flexibility from consumers of the library to be able to stop the connect process immediately.The reason why is that the
handleConnection
method is taking in aproxy.Dialer
which doesn't contain adialer.DialContext
method required to cancel the connection mid-way with a cancellation signal.As a solution, we can cast the
proxy.Dialer
to aproxy.ContextDialer
and let the call toStop()
properly exit the connection process with the use of a context onhandleConnection
.