Skip to content

fix: Add isFirst check before err check #4326

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

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,21 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, logger slog.Logg
// Need to disable compression to avoid a data-race.
CompressionMode: websocket.CompressionDisabled,
})
if err != nil {
if errors.Is(err, context.Canceled) {
return
}
logger.Debug(ctx, "failed to dial", slog.Error(err))
continue
}
if isFirst {
if res.StatusCode == http.StatusConflict {
if err != nil && res.StatusCode == http.StatusConflict {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be err == nil? Thinking this will still have the potential nil pointer deref if err != nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, you're correct. I'll fix this now in another PR. I merged due to panic of main being busted!

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems the error isn't nil there actually, so a weird case. I'm just going to check for the status code, then it should be fine!

Copy link
Member Author

Choose a reason for hiding this comment

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

first <- readBodyAsError(res)
return
}
isFirst = false
close(first)
}
if err != nil {
if errors.Is(err, context.Canceled) {
return
}
logger.Debug(ctx, "failed to dial", slog.Error(err))
continue
}
sendNode, errChan := tailnet.ServeCoordinator(websocket.NetConn(ctx, ws, websocket.MessageBinary), func(node []*tailnet.Node) error {
return conn.UpdateNodes(node)
})
Expand Down