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.

var disposeCallbackState = (StreamDisposeCallbackState)state;
if (!disposeCallbackState.TryChangeStateFromInProgress(OperationState.Cancelled))
{
// if cannot change the state - then I/O was already succeeded
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: "It the state can't be changed- then I/O had already succeeded"

catch (IOException)
{
if (callbackState?.OperationState == OperationState.Cancelled)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining that Cancelled means both cancelationtoken cancelation and timeout.


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.


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.

manualResetEvent);

if (writeOperation.IsCompleted || manualResetEvent.Wait(timeout, cancellationToken))
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.

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