Skip to content

mssqlserver: guard Connect against concurrent calls#4288

Open
mmatczuk wants to merge 1 commit intomainfrom
mmt/mssqlserver-guard-connect-against-concurrent-calls
Open

mssqlserver: guard Connect against concurrent calls#4288
mmatczuk wants to merge 1 commit intomainfrom
mmt/mssqlserver-guard-connect-against-concurrent-calls

Conversation

@mmatczuk
Copy link
Copy Markdown
Contributor

The benthos framework can call Connect() concurrently or re-enter it
before the background goroutine has stopped. Without a guard, two
goroutines share the same publisher and checkpoint tracker, corrupting
state and causing the streaming phase to hang indefinitely.

Add a mutex and a HasStoppedChan check so that a second Connect() is
a no-op while the previous goroutine is still running.

Fixes CON-389

The benthos framework can call Connect() concurrently or re-enter it
before the background goroutine has stopped. Without a guard, two
goroutines share the same publisher and checkpoint tracker, corrupting
state and causing the streaming phase to hang indefinitely.

Add a mutex and a HasStoppedChan check so that a second Connect() is
a no-op while the previous goroutine is still running.

Fixes CON-389
@claude
Copy link
Copy Markdown

claude bot commented Apr 16, 2026

Commits
LGTM

Review
Small, focused fix that adds a mutex and HasStoppedChan guard to Connect() to prevent concurrent/re-entrant calls from corrupting shared state. The mutex is correctly scoped inside the method (per mutex encapsulation rules), and the stopSig check correctly distinguishes "goroutine still active" from "ready to reconnect."

LGTM

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.

1 participant