Skip to content

Conversation

@sanych-sun
Copy link
Member

@sanych-sun sanych-sun commented Oct 31, 2025

The PR is created based on 3.5.x branch, here is the custom EG patch to validate it's green:
https://spruce.mongodb.com/version/69052114d023dd0007b247d7

@sanych-sun sanych-sun requested a review from a team as a code owner October 31, 2025 20:47
@sanych-sun sanych-sun requested review from BorisDog and ajcvickers and removed request for a team and ajcvickers October 31, 2025 20:47
@sanych-sun sanych-sun added the bug Fixes issues or unintended behavior. label Oct 31, 2025
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Looks good, few small comments.


cancellationToken.ThrowIfCancellationRequested();
throw new TimeoutException();
return UseStreamWithTimeout(
Copy link
Contributor

Choose a reason for hiding this comment

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

Few naming suggestions:
UseStreamWithTimeout -> rename to ExecuteOperationWithTimeout?
method -> rename to operation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}
}

private static TResult UseStreamWithTimeout<TResult, TState>(Stream stream, Func<Stream, TState, TResult> method, TState state, TimeSpan timeout, CancellationToken cancellationToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just
byte[] buffer, int offset, int count instead of state, as it's the same in both cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've switched to using ValueTuple, otherwise int parameters of the Func operation might be ambiguous.

@sanych-sun
Copy link
Member Author

The latest changes build: https://spruce.mongodb.com/version/6912484caf54450007c31989

@sanych-sun sanych-sun requested a review from BorisDog November 11, 2025 00:06
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Minor comments.


private static TResult ExecuteOperationWithTimeout<TResult>(Stream stream, Func<Stream, (byte[] Buffer, int Offset, int Count), TResult> operation, byte[] buffer, int offset, int count, TimeSpan timeout, CancellationToken cancellationToken)
{
StreamDisposeCallbackState callbackState = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have tests to test all the major cases here? Timeout, cancellation, success.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests added.


cancellationToken.ThrowIfCancellationRequested();
throw new TimeoutException();
return ExecuteOperationWithTimeout(
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: can use expression body.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@sanych-sun sanych-sun requested a review from BorisDog November 12, 2025 20:26
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM

var stream = streamMock.Object;

var destination = new byte[2];
using var cancellationTokenSource = new CancellationTokenSource(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

@sanych-sun sanych-sun merged commit 77d5ed7 into mongodb:v3.5.x Nov 12, 2025
5 checks passed
@sanych-sun sanych-sun deleted the csharp5777 branch November 12, 2025 21:36
sanych-sun added a commit to sanych-sun/mongo-csharp-driver that referenced this pull request Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants