Skip to content

Fix a bug where we would not flush messages before waiting for a response#705

Merged
LukeButters merged 4 commits intomainfrom
luke/flush-messages
Mar 29, 2026
Merged

Fix a bug where we would not flush messages before waiting for a response#705
LukeButters merged 4 commits intomainfrom
luke/flush-messages

Conversation

@LukeButters
Copy link
Copy Markdown
Contributor

@LukeButters LukeButters commented Mar 26, 2026

Background

ref CLOUDPT-11160
ref EFT-3141

Fixes a bug where if the RequestMessage has no data stream, we would not flush it and so we could be in a situation where by both ends are waiting for data to be sent. Since the sender has not flushed the request but is waiting for a response, while the receiver is waiting for the request to be sent.

Shout out to @sahanocto and claude for finding the issue.

Results

Before

Test failed

After

Test passes.

How to review this PR

Quality ✔️

Pre-requisites

  • I have read How we use GitHub Issues for help deciding when and where it's appropriate to make an issue.
  • I have considered informing or consulting the right people, according to the ownership map.
  • I have considered appropriate testing for my change.

@LukeButters LukeButters marked this pull request as ready for review March 26, 2026 02:03
@LukeButters LukeButters requested a review from a team as a code owner March 26, 2026 02:03
var serializedStreams = await serializer.WriteMessageAsync(stream, message, cancellationToken);
await WriteEachStreamAsync(serializedStreams, cancellationToken);

await stream.FlushAsync(cancellationToken);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The fix

Copy link
Copy Markdown
Contributor

@rhysparry rhysparry left a comment

Choose a reason for hiding this comment

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

✅ LGTM


for (var i = 0; i < clientAndServiceTestCase.RecommendedIterations; i++)
{
var result = await echo.SayHelloAsync("hello");
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.

With the fix omitted, this fails with "Attempted to read past the end of the stream" (and takes 30-45 seconds to do so for each of the three combinations on my machine).

Not sure if it's worth improving the failure behaviour, but if something obvious can be improved here that could help in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably not, its not something we can obviously improve.

/// A stream that buffers all writes in memory and only forwards them to the underlying
/// stream when Flush or FlushAsync is called.
/// </summary>
public class FlushBufferedStream : DelegateStreamBase
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.

Is it worth including 'Unbounded' or 'Test' in the name here? I wouldn't want to see this class go wandering outside of tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed to start with TestOnly

@LukeButters LukeButters merged commit 1c1d330 into main Mar 29, 2026
17 checks passed
@LukeButters LukeButters deleted the luke/flush-messages branch March 29, 2026 23:43
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