Skip to content

Fix flaky DuplexTest.duplexWithAuthChallenge#9564

Closed
kamilkrzywanski wants to merge 1 commit into
lysine-dev:masterfrom
kamilkrzywanski:fix/duplex-auth-challenge-flake
Closed

Fix flaky DuplexTest.duplexWithAuthChallenge#9564
kamilkrzywanski wants to merge 1 commit into
lysine-dev:masterfrom
kamilkrzywanski:fix/duplex-auth-challenge-flake

Conversation

@kamilkrzywanski

Copy link
Copy Markdown

Summary

Fixes #9370.

On Windows (and occasionally elsewhere), duplexWithAuthChallenge fails with:

StreamResetException: stream was reset: CANCEL
  at MockSocketHandler.sendResponse (flush)
  at MockSocketHandler.awaitSuccess

The client can act on the 401 and cancel the HTTP/2 stream while the server is still writing the duplex challenge body. That is the same race fixed for duplexWithRedirect in #4788.

Change

Reuse that pattern:

  1. CountDownLatch counted down after the server sends "please authenticate!\n"
  2. EventListener.requestHeadersEnd awaits the latch so the client does not process the 401 (and reset the stream) until that write has finished

Test plan

  • ./gradlew :okhttp:jvmTest --tests okhttp3.DuplexTest.duplexWithAuthChallenge (×5)
  • ./gradlew :okhttp:jvmTest --tests okhttp3.DuplexTest.duplexWithRedirect
  • spotlessCheck

Same race as duplexWithRedirect: the client can process the 401 and
reset the stream before MockSocketHandler finishes writing the challenge
body. Wait for that write (as duplexWithRedirect already does) before
continuing past request headers.

Fixes lysine-dev#9370
@JakeWharton

Copy link
Copy Markdown
Collaborator

See #9563 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

DuplexTest.duplexWithAuthChallenge flaky

2 participants