iso8583-connection icon indicating copy to clipboard operation
iso8583-connection copied to clipboard

Issue: Possible Bug in recreateConnection function

Open scarballo opened this issue 6 months ago • 1 comments

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:

  1. Establish the Initial Connection:

    • Start the main service and establish a connection to a test service.
  2. Stop the Test Service:

    • Manually stop the test service to simulate a connection issue.
  3. Wait for a Duration:

    • Keep the test service stopped for a duration longer than the value configured in the PoolReconnectWait option.
  4. Observe the Error Message:

    • You should see the following line in the main service logs:
      "failed to re-create connection for...."
      
  5. Re-Start the Test Service:

    • Restart the test service. Notice that the connection is never re-established, confirming the bug.
  6. Apply the Fix:

    • Modify the recreateConnection function by replacing the return statement with a continue statement.
  7. 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.

scarballo avatar Aug 12 '24 07:08 scarballo