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/rpc: race condition in Server.ServeCodec #17239

Closed
willfaught opened this issue Sep 26, 2016 · 6 comments
Closed

net/rpc: race condition in Server.ServeCodec #17239

willfaught opened this issue Sep 26, 2016 · 6 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@willfaught
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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

It was 1.6 (on a work computer I don't have access to anymore).

What operating system and processor architecture are you using (go env)?

It was Mac OS 10.11 (on a work computer I don't have access to anymore).

What did you do?

There's a race condition in Server.ServeCodec, where the connection is closed without waiting for all calls to finish:

477         go service.call(server, sending, mtype, req, argv, replyv, codec)
478     }
479     codec.Close()

In this code, the go statement is executed in a loop, and then the codec is closed immediately after the loop ends, which in the case of the jsonrpc codec closes the connection used by the calls before they can finish, resulting in errors.

@quentinmit
Copy link
Contributor

/cc @robpike @rsc @adg

I think the intent here is for the loop to block again when it loops on readRequest.

How are you managing to exit the loop?

We could of course fix this by adding a sync.WaitGroup to track the outstanding RPCs, but then you would not be able to tell from the RPC handler when the connection is closed and you should abort.

@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 4, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Oct 4, 2016
@robpike
Copy link
Contributor

robpike commented Oct 4, 2016

If this is related to #5792, as I think it is, it's really hard to fix. The read half is relatively easy but the write half is not. See also #16844, which was introduced partly in response to this problem.

@willfaught
Copy link
Contributor Author

How are you managing to exit the loop?

By closing the connection to shut down the server gracefully.

@rsc rsc self-assigned this Oct 6, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8Maybe Nov 2, 2016
@bradfitz bradfitz modified the milestones: Go1.10, Go1.9 Jun 7, 2017
@rsc
Copy link
Contributor

rsc commented Nov 22, 2017

CL sent.

@gopherbot
Copy link

Change https://golang.org/cl/79515 mentions this issue: net/rpc: wait for responses to be written before closing Codec

@willfaught
Copy link
Contributor Author

Awesome! Thanks @rsc!

@golang golang locked and limited conversation to collaborators Nov 29, 2018
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants