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

RSDK-9316 Disallow client stream creation when channel has been closed #394

Merged
merged 4 commits into from
Nov 20, 2024

Conversation

benjirewis
Copy link
Member

@benjirewis benjirewis commented Nov 20, 2024

RSDK-9316

Checks the underlying channel's context for error before creating a new client stream. Returns a new ErrDisconnected error if the context has errored. A PR like this one would make rdk sensitive to that new error instead of just waiting for io.ErrClosedPipe after an eventual read/write (?) from/to the closed channel.

Confirmed that this PR plus the linked rdk one gets rid of the race seen in viamrobotics/rdk#4566 CI.

@viambot viambot added the safe to test Mark as safe to test label Nov 20, 2024
@benjirewis benjirewis marked this pull request as ready for review November 20, 2024 20:34
@benjirewis
Copy link
Member Author

Needs a test; adding one.

@@ -45,7 +50,14 @@ func newWebRTCClientStream(
stream *webrtcpb.Stream,
onDone func(id uint64),
logger utils.ZapCompatibleLogger,
) *webrtcClientStream {
) (*webrtcClientStream, error) {
// Assume that cancelation of the client channel's context means the peer
Copy link
Member

Choose a reason for hiding this comment

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

This is a good start to a comment. But I feel like there's a bit of "what's the consequence of removing this"? This just looks like an optimization to inform the caller sooner that their invocation/stream isn't going to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some elaboration there; let me know what you think. Thanks for asking for more, will be helpful for posterity.

Copy link
Member

Choose a reason for hiding this comment

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

Much better!

I'd also note (because it's very not obvious in this case) the caller is holding the channel mutex that's also acquired in the "close" code path that's canceling this context.

Copy link
Member Author

Choose a reason for hiding this comment

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

For sure; included (almost) exactly what you said there.

@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 20, 2024
@viambot viambot added safe to test Mark as safe to test and removed safe to test Mark as safe to test labels Nov 20, 2024
@benjirewis benjirewis merged commit 96c17f9 into viamrobotics:main Nov 20, 2024
6 checks passed
@benjirewis benjirewis deleted the no-client-stream-when-closed branch November 20, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test Mark as safe to test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants