Skip to content

Conversation

@awly
Copy link
Member

@awly awly commented Jul 12, 2023

When Logger.Startup is called and a new http.Client is initialized for logtail, nl.logger is nil. It's initialized right after creating the http.Client. But because we're passing a method value, it actually works and passes the value with a nil receiver.
Later, when logtail.Logger.Logf is called from the http.Client, tailscaled panics when trying to access the fields of that nil logger.

When `Logger.Startup` is called and a new `http.Client` is initialized
for logtail, `nl.logger` is nil. It's initialized right after creating
the `http.Client`. But because we're passing a method value, it actually
works and passes the value with a `nil` receiver.
Later, when `logtail.Logger.Logf` is called from the `http.Client`,
`tailscaled` panics when trying to access the fields of that nil logger.

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
@awly awly requested a review from andrew-d July 12, 2023 20:44
Copy link
Member

@andrew-d andrew-d left a comment

Choose a reason for hiding this comment

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

Very good catch, thank you 🤦 Optional, but if you feel like it... we could pull out the log.Printf from the call to logtail.NewLogger into a shared variable between that function and logpolicy.NewLogtailTransport. We can always do that later after this fix though 😄

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
@awly
Copy link
Member Author

awly commented Jul 13, 2023

@andrew-d updated, is this what you meant?

Copy link
Member

@andrew-d andrew-d left a comment

Choose a reason for hiding this comment

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

@andrew-d updated, is this what you meant?

Yeah, exactly; thanks! Please make sure to squash this into the first commit, but otherwise LGTM 🎉

@awly awly merged commit 354885a into main Jul 13, 2023
@awly awly deleted the awly/logtail-nil-panic-fix branch July 13, 2023 15:54
alexelisenko pushed a commit to Control-D-Inc/tailscale that referenced this pull request Feb 15, 2024
Signed-off-by: Alex Paguis <alex@windscribe.com>
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.

2 participants