Skip to content

Conversation

@juanfont
Copy link
Owner

@juanfont juanfont commented Jun 8, 2021

The issue occurs when a client closes the connection. We receive cancellation of the gin context here https://github.com/juanfont/headscale/blob/main/api.go#L322. Because of the defer close(update) in PollNetMapHandler we were closing the channel outside the mutex so it can happen that a new client arrives and tries to notify its peers - including the one that just closed the connection https://github.com/juanfont/headscale/blob/main/api.go#L288

Fixes #32.

now := time.Now().UTC()
m.LastSeen = &now
db.Save(&m)
h.pollMu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we want to keep this call to Lock() ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I moved it a few lines up, to cover also the DB access... Not really needed though...

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not needed, let's keep it where it was to keep the lock as short as possible? LGTM otherwise!

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fully agreed. Sent another commit and proceeding with merge :)

@juanfont juanfont merged commit 6e86b2a into main Jun 9, 2021
@juanfont juanfont deleted the fix-polling-race branch June 9, 2021 18:57
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.

Times out

3 participants