feat: add ConnectContext for context-aware connection#83
Open
semihbkgr wants to merge 1 commit intorobinson:masterfrom
Open
feat: add ConnectContext for context-aware connection#83semihbkgr wants to merge 1 commit intorobinson:masterfrom
semihbkgr wants to merge 1 commit intorobinson:masterfrom
Conversation
Add ConnectContext(ctx context.Context) method to TCPClientHandler, enabling callers to cancel in-flight TCP dials via context (e.g., during graceful shutdown). This follows the Go stdlib pattern where DialContext was added alongside Dial in net.Dialer. Connect() now delegates to ConnectContext(context.Background()), keeping full backward compatibility with no behavior change. Closes robinson#82 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
ConnectContext(ctx context.Context)method toTCPClientHandler, enabling callers to cancel in-flight TCP dials via context (e.g., during graceful shutdown)Connect()now delegates toConnectContext(context.Background())— full backward compatibility, no behavior changenet.Dialer.Dial→net.Dialer.DialContext,sql.DB.Query→sql.DB.QueryContext)Motivation
The current
Connect()usesnet.Dialer.Dial()internally, which doesn't supportcontext.Context. When a caller needs to cancel a connection attempt (e.g., during graceful shutdown), the TCP dial blocks for the full timeout duration with no way to abort it.ConnectContextusesnet.Dialer.DialContext()instead, allowing immediate cancellation via context.Closes #82