quickfixgo / quickfix

The Go FIX Protocol Library :rocket:
https://www.quickfixgo.org/
Other
735 stars 288 forks source link

Calling Stop() on Initiator blocks on Dial method #653

Closed abronan closed 1 month ago

abronan commented 2 months ago

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.