Skip to content

fix: prevent check_connections from dropping connections during setup#387

Merged
BewareMyPower merged 1 commit intostreamnative:masterfrom
mezmo:fix_connection_manager_race
Jan 15, 2026
Merged

fix: prevent check_connections from dropping connections during setup#387
BewareMyPower merged 1 commit intostreamnative:masterfrom
mezmo:fix_connection_manager_race

Conversation

@darinspivey
Copy link
Contributor

When using topic_regex or multi-topic consumers, there is a race condition between getting a connection for topic refresh and the check_connections cleanup task. The strong_count check could cause connections to be dropped if check_connections runs while connect() is in progress, since connect() temporarily downgrades the Arc ref.

This commit adds a 5-second grace period for newly created connections, allowing them to be picked up by consumers/producers before being considered for cleanup.

Fixes: #386

When using topic_regex or multi-topic consumers, there is a race
condition between getting a connection for topic refresh and the
check_connections cleanup task. The strong_count check could cause
connections to be dropped if check_connections runs while connect()
is in progress, since connect() temporarily downgrades the Arc ref.

This commit adds a 5-second grace period for newly created connections,
allowing them to be picked up by consumers/producers before being
considered for cleanup.

Fixes: streamnative#386
@darinspivey darinspivey force-pushed the fix_connection_manager_race branch from ce5272b to ff62b0a Compare January 14, 2026 18:25
@darinspivey
Copy link
Contributor Author

@BewareMyPower you've been helping review some of @chamons contributions recently, and this PR pertains to those (PR #384 ). Now that update_topics() is being called for all multi consumers, the race condition described in this PR will be more frequent. This provides a fix that I've tested locally.

Thanks in advance.

@BewareMyPower BewareMyPower merged commit 771b6ef into streamnative:master Jan 15, 2026
8 checks passed
Copy link
Contributor

@chamons chamons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks reasonable to me, good catch.

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.

Race Condition in check_connections Dropping Active Connections

3 participants