Repository navigation
Conversation
Add idempotent closeConnection and release sockets when initialization or authentication fails or is cancelled. BREAKING CHANGE: failed operations invalidate their connection. Further operations raise ConnectionClosed; callers must open a fresh handle to retry.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the third fix, and it involves an API behavior change I'd appreciate your feedback on. While testing a connection pool with bounded readiness checks, I encountered problems with cancellation and failed-connection disposal.
withConnectionreconnects inside its exception handler, including after a timeout. Cleanup can therefore enter another connection attempt and authentication. If reconnection throws, the connection-stateMVarremains empty, so later operations can wait indefinitely. Failed or cancelled initialization/authentication can also leave sockets open, and I couldn't find a public close operation for pool disposal.This proposes closing and invalidating failed handles instead of reconnecting during exception cleanup. It also releases resources when initialization fails and exports an idempotent
closeConnection. Subsequent operations raiseConnectionClosed; callers must open a fresh handle to retry. The existing error-test example has been updated accordingly.closeConnectionwaits for active operations, so owners should stop concurrent use before disposal.The connection-lifecycle-regressions suite passes on
GHC 9.12.4, covering initialization/authentication failures, cancellation, repeated close, invalidated-handle reuse, and a throwing close callback. It uses real allocated sockets with scripted IO. The updated t004-errors executable also builds. I haven't run the full compiler matrix or live-server suite for this branch.Would explicit reopening fit the intended API? If automatic recovery should be preserved, I'm happy to discuss an alternative that keeps reconnection out of cancellation cleanup.