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

refactor: use *http.ServeMux #72

Merged
merged 3 commits into from
Aug 7, 2024
Merged

Conversation

dwisiswant0
Copy link
Member

Make *http.Server.Shutdown works with *http.ServeMux.

So it can defer the *Statistics.Stop (projectdiscovery/httpx#1856).

@dwisiswant0 dwisiswant0 requested a review from Mzack9999 August 7, 2024 01:37
instead of default multiplexer.

also shutdown with current context

Signed-off-by: Dwi Siswanto <[email protected]>
@dwisiswant0 dwisiswant0 force-pushed the refactor/use-http-ServeMux-instead branch from 82c5091 to a4d47a9 Compare August 7, 2024 01:39
@dwisiswant0 dwisiswant0 requested a review from ehsandeep August 7, 2024 12:23
Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

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

lgtm!

Unrelated to this PR, but what do you think about also using something like this within the start:

errChan := make(chan error, 1)
var done atomic.Bool

go func() {
	if err := s.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed && !done.Load() {
		errChan <- err
	}
}()

// catch initial fatal errors
select {
	case err := <-errChan:
		return err
	case <-time.After(250 * time.Millisecond):
		done.Store(true)
		close(errChan)
}

to catch s.httpServer.ListenAndServe() errors in Statistics.Start(...)

@dwisiswant0
Copy link
Member Author

@Mzack9999 - I was thinking about immediately returning ListenAndServe and invoking Statistics.Start using goroutine. It seems like this approach needs to be tested out.

@dwisiswant0 dwisiswant0 merged commit 3294cde into main Aug 7, 2024
4 checks passed
@dwisiswant0 dwisiswant0 deleted the refactor/use-http-ServeMux-instead branch August 7, 2024 20:53
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