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

cmd/tailscaled, tsnet: don't return an interface containing a nil pointer #10752

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

andrew-d
Copy link
Member

@andrew-d andrew-d commented Jan 5, 2024

This tripped me up when I was testing something and wrote:

if conn != nil {
    conn.Close()
}

In netstack mode, when an error occurred we were getting a non-nil error and a non-nil interface that contained a nil pointer. Instead, just return a nil interface value.

Updates #cleanup

Change-Id: Id9ef3dd24529e0e8c53adc60ed914c31fbb10cc4

…nter

This tripped me up when I was testing something and wrote:

    if conn != nil {
        conn.Close()
    }

In netstack mode, when an error occurred we were getting a non-nil error
and a non-nil interface that contained a nil pointer. Instead, just
return a nil interface value.

Updates #cleanup

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: Id9ef3dd24529e0e8c53adc60ed914c31fbb10cc4
Copy link
Contributor

@icio icio left a comment

Choose a reason for hiding this comment

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

Ah yeah, this is a friendly improvement.

@@ -511,7 +511,13 @@ func getLocalBackend(ctx context.Context, logf logger.Logf, logID logid.PublicID
return ok
}
dialer.NetstackDialTCP = func(ctx context.Context, dst netip.AddrPort) (net.Conn, error) {
return ns.DialContextTCP(ctx, dst)
// Note: don't just return ns.DialContextTCP or we'll
// return an interface containing a nil pointer.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments are good but it might be worth writing a little test to ensure there's no regressions of this behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried that, but it's super annoying to test this since it's in the main package, and requires a running Tailscale backend to even get this far 😵‍💫

@andrew-d andrew-d merged commit 46bdbb3 into main Jan 5, 2024
46 checks passed
@andrew-d andrew-d deleted the andrew/netstack-nil-pointer branch January 5, 2024 16:44
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.

None yet

3 participants