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: race between operations on maxClientStreamID and inGoAway. #51309

Open
doujiang24 opened this issue Feb 22, 2022 · 4 comments
Open

net/http: race between operations on maxClientStreamID and inGoAway. #51309

doujiang24 opened this issue Feb 22, 2022 · 4 comments
Labels
WaitingForInfo

Comments

@doujiang24
Copy link
Contributor

@doujiang24 doujiang24 commented Feb 22, 2022

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

$ go version
go version go1.17.2 darwin/amd64

Does this issue reproduce with the latest release?

yeah, maybe. I haven't reproduced it yet.
Just found this issue based on code.

race may happen on such a flow:


 fields                                 write goroutine                       read goroutine

                                                                         1. read(false), in processHeaders
inGoAway
                                       2. set to true, in goAway
----------------------------------------------------------
                                       3. read(old), in scheduleFrameWrite 
maxClientStreamID
                                                                        4. set(a new), in processHeaders

The server may have already processed the new request while the client got the old stream id in the GoAway frame,
and the client will retry the new request again.

Yeah, the race is very very small, but I think it indeed exists in theory.
eg. these three things happen at the same time:

  1. server received a request header,
  2. server got a signal to start graceful stop,
  3. an OS schedule on the read goroutine between operation 1 and operation 4(make it is long enough time).

Or, do I misunderstand the code?
Thanks!

@mengzhuo
Copy link
Contributor

@mengzhuo mengzhuo commented Feb 22, 2022

Can you build your exmaple code with -race ?
https://go.dev/doc/articles/race_detector

@mengzhuo mengzhuo added the WaitingForInfo label Feb 22, 2022
@mengzhuo mengzhuo changed the title net/http: server: maybe a little race between operations on maxClientStreamID and inGoAway. net/http: race between operations on maxClientStreamID and inGoAway. Feb 22, 2022
@doujiang24
Copy link
Contributor Author

@doujiang24 doujiang24 commented Feb 22, 2022

@mengzhuo Thanks for your reply.
In my opinion, it's hard to build a reproducible example even with -race.

I think the key point is:
we assume there may be a long time between these two lines, eg. an OS schedule that -race can not simulate.
https://github.com/golang/go/blob/master/src/net/http/h2_bundle.go#L5525-L5565

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 22, 2022

CC @neild to see if there is a race in the net/http code.

@doujiang24
Copy link
Contributor Author

@doujiang24 doujiang24 commented Mar 3, 2022

@neild Could you please take a look at this issue? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo
Projects
None yet
Development

No branches or pull requests

3 participants