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

net/http/httptest: Server.Start shouldn't return until it really can Accept connections #23757

Closed
hzxuzhonghu opened this issue Feb 9, 2018 · 8 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@hzxuzhonghu
Copy link

hzxuzhonghu commented Feb 9, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

latest

Does this issue reproduce with the latest release?

yes

What did you do?

After call httptest.Server.Start or StartTLS, I want the server is ready to serve any request. But unfortunately it takes some time to be ready.

@bradfitz
Copy link
Contributor

bradfitz commented Feb 9, 2018

I want the server is ready to serve any request. But unfortunately it takes some time to be ready.

Why?

That's not intentional, and I've never experienced that.

If there's a problem, the fix is to make Start do the right thing, and not to add more API like Wait.

Why do you think Start doesn't work immediately? Got a reproducible example of a failure? Or an idea of why the code is wrong?

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 9, 2018
@davecheney
Copy link
Contributor

davecheney commented Feb 9, 2018 via email

@bradfitz bradfitz changed the title httptest.Server.Start should return until it really can Accept connections net/http/httptest: Server.Start shouldn't return until it really can Accept connections Feb 9, 2018
@hzxuzhonghu
Copy link
Author

hzxuzhonghu commented Feb 9, 2018

Because it call Server.goServe which start a new goroutine, and in theory, it takes time.

@hzxuzhonghu
Copy link
Author

@bradfitz I think we can notify the parent goroutine when the below goroutine is running.

func (s *Server) goServe() {
	s.wg.Add(1)
	go func() {
		defer s.wg.Done()
		s.Config.Serve(s.Listener)
	}()
}

@bradfitz
Copy link
Contributor

bradfitz commented Feb 9, 2018

But the net.Listener is already listening before that's called. So it'll still accept the connection, and then in a tiny amount of time (under milliseconds) it'll handle it.

I see no problem.

@hzxuzhonghu
Copy link
Author

Oh, so i missed the listener.

@bradfitz
Copy link
Contributor

bradfitz commented Feb 9, 2018

No worries. Glad there's not a problem to fix. :)

@hzxuzhonghu
Copy link
Author

Thank you .

@golang golang locked and limited conversation to collaborators Feb 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants