Skip to content

replication: fix BinlogSyncer.Close hang on SSH tunnels#1128

Merged
lance6716 merged 2 commits into
go-mysql-org:masterfrom
serprex:fix-binlog-close-deadlock
May 2, 2026
Merged

replication: fix BinlogSyncer.Close hang on SSH tunnels#1128
lance6716 merged 2 commits into
go-mysql-org:masterfrom
serprex:fix-binlog-close-deadlock

Conversation

@serprex

@serprex serprex commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

SetReadDeadline unblocks ReadPacket so onStream notices ctx cancellation. Some transports (notably SSH tunnels) refuse deadlines with an error, in which case close the underlying connection to force ReadPacket to return. Otherwise wg.Wait below parks forever when KILL also fails to reach server (e.g. thread already reaped, "ERROR 1094 unknown thread id")

see PeerDB-io/peerdb#4195

@serprex serprex force-pushed the fix-binlog-close-deadlock branch from 390e9be to 23a677d Compare April 21, 2026 16:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the close method in BinlogSyncer to ensure the underlying connection is closed if SetReadDeadline fails. This change prevents potential deadlocks when using transports that do not support deadlines, such as SSH tunnels. A new test case, TestCloseUnblocksWhenSetReadDeadlineFails, along with a mock connection type, has been added to verify this behavior. I have no feedback to provide.

SetReadDeadline unblocks ReadPacket so onStream notices ctx cancellation.
Some transports (notably SSH tunnels) refuse deadlines with an error, in
which case close the underlying connection to force ReadPacket to return.
Otherwise wg.Wait below parks forever when KILL also fails to reach server
(e.g. thread already reaped, "ERROR 1094 unknown thread id")
@serprex serprex force-pushed the fix-binlog-close-deadlock branch from 23a677d to 72c85c9 Compare April 21, 2026 17:00

@lance6716 lance6716 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for the late review

@lance6716 lance6716 merged commit 069f15d into go-mysql-org:master May 2, 2026
24 checks passed
dbnski pushed a commit to dbnski/go-mysql that referenced this pull request Jul 10, 2026
…#1128)

SetReadDeadline unblocks ReadPacket so onStream notices ctx cancellation.
Some transports (notably SSH tunnels) refuse deadlines with an error, in
which case close the underlying connection to force ReadPacket to return.
Otherwise wg.Wait below parks forever when KILL also fails to reach server
(e.g. thread already reaped, "ERROR 1094 unknown thread id")

Co-authored-by: lance6716 <lance6716@gmail.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.

2 participants