Skip to content

Conversation

@mihaip
Copy link
Contributor

@mihaip mihaip commented Oct 13, 2022

NewNetcheckClient only initializes a subset of fields of derphttp.Client, and it's exepcted that only DialRegionTLS is called on it. We do not need to close it (as added by #5707), and it's an error to do so.

Fixes #5919

@mihaip mihaip requested a review from bradfitz October 13, 2022 18:12
Comment on lines 1191 to 1192
// We intentionally do not Close() the derphttp Client, as it's only
// partially initialized.
Copy link
Member

Choose a reason for hiding this comment

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

Can we make Close safe instead?

Otherwise I fear that static analysis like @odeke-em's from his https://github.com/tailscale/tailscale/pulls?q=is%3Apr+is%3Aclosed+author%3Aodeke-em+leaks changes will just keep flagging this as not closed and we'll be in this same position later.

Copy link
Contributor Author

@mihaip mihaip Oct 13, 2022

Choose a reason for hiding this comment

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

I figured the comment would be enough to get people not add Close() calls blindly, but you're right that other uses could crop up.

…ient

NewNetcheckClient only initializes a subset of fields of derphttp.Client,
and the Close() call added by #5707 was result in a nil pointer dereference.
Make Close() safe to call when using NewNetcheckClient() too.

Fixes #5919

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
@mihaip mihaip force-pushed the mihaip/derp-close branch from 2c6f28f to a446b21 Compare October 13, 2022 18:29
Copy link
Contributor

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Thank you @mihaip! Thanks for the co-review and tag @bradfitz!

@mihaip mihaip merged commit b2855cf into main Oct 13, 2022
@mihaip mihaip deleted the mihaip/derp-close branch October 13, 2022 18:49
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.

nil pointer dereference when running tailscale netcheck

3 participants