net: manager owns net lifecycle (auto-start/close, ownership-gated)#3118
Merged
Conversation
Make KafkaConnectionManager self-sufficient for direct use: track net
ownership (owned iff the manager created it -- net arg is None or a name
string, not a passed-in NetBackend instance), auto-start the owned net lazily
on the blocking entry points (run/bootstrap), and close it in close(). This
lets a direct manager user do KafkaConnectionManager(bootstrap_servers=...)
then bootstrap()/run() with no explicit _net.start()/close() -- and advances
Phase-D (manager as the entry point, not the compat shim).
Ownership gating is what keeps it safe:
- Auto-start only on run()/bootstrap() (blocking user entry points), NOT on
the internal fire-and-forget call_soon() -- which cluster/sender/coordinator
call and which must not spin up a thread.
- on_io_thread() guard on the auto-close so close() from a produce callback
(on the IO thread) doesn't try to join that thread.
- The unit-test harness passes an *instance* (unstarted NetworkSelector it
drives via drain()/poll()) -> not owned -> untouched.
KafkaNetClient (the legacy poll()-driving shim) manages its net lifecycle
explicitly (start/poll/close), so it now resolves + creates its own net and
hands the manager a ready instance -- ownership follows creation, and the
manager does NOT auto-start/close it (which would collide with the shim's
net.poll() driving). Direct KafkaConnectionManager(net=None) users get the
auto lifecycle instead.
Co-Authored-By: Claude Opus 4.8 (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.
Make KafkaConnectionManager self-sufficient for direct use: track net
ownership (owned iff the manager created it -- net arg is None or a name
string, not a passed-in NetBackend instance), auto-start the owned net lazily
on the blocking entry points (run/bootstrap), and close it in close(). This
lets a direct manager user do KafkaConnectionManager(bootstrap_servers=...)
then bootstrap()/run() with no explicit _net.start()/close() -- and advances
Phase-D (manager as the entry point, not the compat shim).
Ownership gating is what keeps it safe:
the internal fire-and-forget call_soon() -- which cluster/sender/coordinator
call and which must not spin up a thread.
(on the IO thread) doesn't try to join that thread.
drives via drain()/poll()) -> not owned -> untouched.
KafkaNetClient (the legacy poll()-driving shim) manages its net lifecycle
explicitly (start/poll/close), so it now resolves + creates its own net and
hands the manager a ready instance -- ownership follows creation, and the
manager does NOT auto-start/close it (which would collide with the shim's
net.poll() driving). Direct KafkaConnectionManager(net=None) users get the
auto lifecycle instead.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com