Skip to content

Close connection on responseTo mismatch to prevent pool reuse#1975

Closed
rozza wants to merge 2 commits into
mongodb:mainfrom
rozza:JAVA-6210
Closed

Close connection on responseTo mismatch to prevent pool reuse#1975
rozza wants to merge 2 commits into
mongodb:mainfrom
rozza:JAVA-6210

Conversation

@rozza

@rozza rozza commented May 19, 2026

Copy link
Copy Markdown
Member

When ReplyMessage detects that the responseTo field in a server response does not match the expected requestId, close the underlying connection.

Previously, MongoInternalException propagated as a regular error without closing the stream. Since PooledConnection.close() only prunes connections that are closed or match shouldPrune() criteria (generation, idle time, lifetime), the desynchronized connection was returned to the pool and could be handed to subsequent operations — risking further data corruption.

A responseTo mismatch means the TCP stream is definitively desynchronized. The connection is unusable and must not be recycled.

JAVA-6210

rozza and others added 2 commits May 19, 2026 13:09
When ReplyMessage detects that the responseTo field in a server response
does not match the expected requestId, close the underlying connection.

Previously, MongoInternalException propagated as a regular error without
closing the stream. Since PooledConnection.close() only prunes connections
that are closed or match shouldPrune() criteria (generation, idle time,
lifetime), the desynchronized connection was returned to the pool and
could be handed to subsequent operations — risking further data corruption.

A responseTo mismatch means the TCP stream is definitively desynchronized.
The connection is unusable and must not be recycled.

JAVA-6210

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rozza rozza marked this pull request as ready for review May 20, 2026 13:45
@rozza rozza requested a review from a team as a code owner May 20, 2026 13:45
@rozza rozza requested a review from strogiyotec May 20, 2026 13:45
@codeowners-service-app

Copy link
Copy Markdown

Assigned stIncMale for team dbx-java because strogiyotec is out of office.

@rozza rozza closed this Jun 8, 2026
@rozza rozza deleted the JAVA-6210 branch June 8, 2026 14:19
@rozza

rozza commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Working on more defensive hardening and will repurpose JAVA-6210 to cover all these cases.

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