iso8583-connection
iso8583-connection copied to clipboard
Issue: Possible Bug in recreateConnection function
Description:
We have identified a potential bug in the recreateConnection function in pool.go file. When there is an issue with the connection, the function attempts to recreate it. However, if an error is thrown during this process, the function currently uses a return statement, which causes the goroutine to stop. As a result, the connection is never successfully recreated.
https://github.com/moov-io/iso8583-connection/blob/d11002cfd50395f295e88eb3e12ebbb4daea1167/pool.go#L221
Proposed Fix:
To address this issue, the return
statement should be replaced with a continue
statement. This change will ensure that the goroutine continues to run and will keep attempting to re-establish the connection until it is successful.
Example to Simulate the Issue:
-
Establish the Initial Connection:
- Start the main service and establish a connection to a test service.
-
Stop the Test Service:
- Manually stop the test service to simulate a connection issue.
-
Wait for a Duration:
- Keep the test service stopped for a duration longer than the value configured in the
PoolReconnectWait
option.
- Keep the test service stopped for a duration longer than the value configured in the
-
Observe the Error Message:
- You should see the following line in the main service logs:
"failed to re-create connection for...."
- You should see the following line in the main service logs:
-
Re-Start the Test Service:
- Restart the test service. Notice that the connection is never re-established, confirming the bug.
-
Apply the Fix:
- Modify the
recreateConnection
function by replacing thereturn
statement with acontinue
statement.
- Modify the
-
Test the Fix:
- Restart the main service and repeat the steps above. This time, the connection should be successfully re-established after the test service is restarted.