Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race issue #22

Closed
wants to merge 3 commits into from
Closed

Fix race issue #22

wants to merge 3 commits into from

Conversation

daveads
Copy link
Contributor

@daveads daveads commented Oct 3, 2024

fix: Resolve race condition in HTTP server handling

  • Implement thread-safe safeServer to wrap http.Server
  • Modify Serve function to use safeServer for improved concurrency
  • Ensure atomic operations for server start and shutdown

This change addresses a race condition in the HTTP server handling,particularly affecting CLI tests. By introducing a safeServer struct with atomic operations and proper synchronization, and prevent potential data races during server startup and shutdown.

Fix for terrastruct/d2#2087

@daveads
Copy link
Contributor Author

daveads commented Oct 3, 2024

@alixander, it's ready for merge, and we can test it afterward.

Copy link
Contributor

@alixander alixander left a comment

Choose a reason for hiding this comment

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

u overwrote the revert?

@daveads
Copy link
Contributor Author

daveads commented Oct 3, 2024

u overwrote the revert?

yea i did...

@daveads
Copy link
Contributor Author

daveads commented Oct 3, 2024

@alixander can we test now ?

or is there a problem...

xhttp/serve.go Outdated
@@ -41,11 +81,12 @@ func Serve(ctx context.Context, shutdownTimeout time.Duration, s *http.Server, l
shutdownCtx, cancel := context.WithTimeout(xcontext.WithoutCancel(ctx), shutdownTimeout)
defer cancel()

err := s.Shutdown(shutdownCtx)
err := ss.Shutdown(shutdownCtx)
<-serverClosed // Wait for server to exit
Copy link
Contributor

Choose a reason for hiding this comment

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

the previous changes were not reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alixander can you just do a reset on the master branch ?

tho i really don't understand why a revert is necessary here.

@daveads daveads closed this Oct 3, 2024
@daveads daveads deleted the fix-race-issue branch October 7, 2024 17:05
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