Skip to content

feat: add ConnectContext for context-aware connection#83

Open
semihbkgr wants to merge 1 commit intorobinson:masterfrom
semihbkgr:feat/connect-context
Open

feat: add ConnectContext for context-aware connection#83
semihbkgr wants to merge 1 commit intorobinson:masterfrom
semihbkgr:feat/connect-context

Conversation

@semihbkgr
Copy link
Copy Markdown

Summary

  • Add ConnectContext(ctx context.Context) method to TCPClientHandler, enabling callers to cancel in-flight TCP dials via context (e.g., during graceful shutdown)
  • Connect() now delegates to ConnectContext(context.Background()) — full backward compatibility, no behavior change
  • Follows the Go stdlib pattern (net.Dialer.Dialnet.Dialer.DialContext, sql.DB.Querysql.DB.QueryContext)

Motivation

The current Connect() uses net.Dialer.Dial() internally, which doesn't support context.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. ConnectContext uses net.Dialer.DialContext() instead, allowing immediate cancellation via context.

Closes #82

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ConnectContext(ctx context.Context) method for context-aware connection

1 participant