Fix flaky auth tests#92
Merged
Merged
Conversation
nathanjcochran
commented
Oct 28, 2025
Comment on lines
-413
to
-415
| // Sleep to ensure the OAuth callback server is listening | ||
| // This prevents "EOF" errors in CI when the server hasn't started yet | ||
| time.Sleep(100 * time.Millisecond) |
Member
Author
There was a problem hiding this comment.
nathanjcochran
commented
Oct 28, 2025
Comment on lines
-171
to
-183
| func (s *oauthServer) Close() error { | ||
| cls := func(closer io.Closer) error { | ||
| if err := closer.Close(); err != nil && !errors.Is(err, net.ErrClosed) { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| return errors.Join( | ||
| cls(s.server), | ||
| cls(s.listener), | ||
| ) | ||
| } |
Member
Author
There was a problem hiding this comment.
I decided to get rid of this function entirely and just call http.Server.Shutdown() directly above. The shutdown method already closes the listener internally, so we shouldn't need to do it ourselves, like it was previously being done here.
murrayju
approved these changes
Oct 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes some flaky auth tests that were sometimes in failing in CI (for example, see here).
The issue manifested as an unexpected EOF from the local OAuth callback server, which was causing the tests to fail here when simulating a request from the user's browser:
I believe it was happening because we were previously doing a non-graceful shutdown of the local HTTP server that handles the callback request. The shutdown was happening after we had already returned a redirect and returned the result on the resultChan, so the code looked valid. However, because the
http.ResponseWriterbuffers data before flushing it to the underlying TCP connection, and we were doing a hard/non-graceful shutdown, the TCP connection was sometimes being closed before the redirect response had actually been flushed, resulting in an EOF for the caller. I heard no reports of this happening outside of CI, but it's possible it could have happened in the wild too.This fixes it by doing a graceful shutdown (which waits for any in-progress requests to complete) instead of a hard shutdown.