Skip to content

fix: flaky test by checking ctx cancellation before racing I/O in protobuf reader/writer - #5591

Merged
akrem-chabchoub merged 2 commits into
masterfrom
fix/ctx-cancellation
Sep 4, 2026
Merged

fix: flaky test by checking ctx cancellation before racing I/O in protobuf reader/writer#5591
akrem-chabchoub merged 2 commits into
masterfrom
fix/ctx-cancellation

Conversation

@akrem-chabchoub

@akrem-chabchoub akrem-chabchoub commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Fixes flaky TestIncoming_ContextTimeout

WriteMsgWithContext and ReadMsgWithContext could behave randomly when the context was already canceled.

They started the I/O operation and waited to see whether the I/O finished or the context was canceled. If both happened at the same time, the program could choose either result.

This was especially easy to reproduce with the in-memory streamtest stream, where I/O could finish immediately. As a result, TestIncoming_ContextTimeout sometimes passed and sometimes failed in CI.

The fix is to check ctx.Err() before starting the I/O. If the context is already canceled or expired, the function now immediately returns the context error every time.

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

@akrem-chabchoub akrem-chabchoub self-assigned this Sep 2, 2026
@akrem-chabchoub akrem-chabchoub added this to the 2026 milestone Sep 2, 2026
@akrem-chabchoub
akrem-chabchoub marked this pull request as ready for review September 2, 2026 09:01
@akrem-chabchoub akrem-chabchoub changed the title fix: fix flaky test by checking ctx cancellation before racing I/O in protobuf reader/writer fix: flaky test by checking ctx cancellation before racing I/O in protobuf reader/writer Sep 2, 2026

if v == nil {
t.Fatal("expected version to be non-nil")
return

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.

why do you need to return here? this is unreachable code. from go doc testing.T:

    A test ends when its Test function returns or calls any of the methods
    T.FailNow, T.Fatal, T.Fatalf, T.SkipNow, T.Skip, or T.Skipf. Those methods,
    as well as the T.Parallel method, must be called only from the goroutine
    running the Test function.

@akrem-chabchoub akrem-chabchoub Sep 4, 2026

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.

Sorry I merged without seeing your comment.
Linter failed and prevented me from push:
7a40425

image

@akrem-chabchoub akrem-chabchoub Sep 4, 2026

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.

I pull master into this branch and run make lint and it works without any issues, although nothing in master is referring to some lint changes, this is wired, didn't know why!

I reverted the changes here: #5598

@akrem-chabchoub
akrem-chabchoub merged commit 38d687d into master Sep 4, 2026
24 of 30 checks passed
@akrem-chabchoub
akrem-chabchoub deleted the fix/ctx-cancellation branch September 4, 2026 06:33
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.

3 participants