[PR #34] [MERGED] Fix a race condition when a client closes the connection #1214

Closed
opened 2025-12-29 02:29:14 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/34
Author: @juanfont
Created: 6/8/2021
Status: Merged
Merged: 6/9/2021
Merged by: @juanfont

Base: mainHead: fix-polling-race


📝 Commits (2)

  • cb1a81f Close the update channel when the client actually closes the connection. Fixes #32.
  • 5db7716 Reduce the mutex size when the client closes the connection

📊 Changes

1 file changed (+7 additions, -6 deletions)

View changed files

📝 api.go (+7 -6)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/34 **Author:** [@juanfont](https://github.com/juanfont) **Created:** 6/8/2021 **Status:** ✅ Merged **Merged:** 6/9/2021 **Merged by:** [@juanfont](https://github.com/juanfont) **Base:** `main` ← **Head:** `fix-polling-race` --- ### 📝 Commits (2) - [`cb1a81f`](https://github.com/juanfont/headscale/commit/cb1a81fe4cda01f974f9f76fe6a50d2c31ba3698) Close the update channel when the client actually closes the connection. Fixes #32. - [`5db7716`](https://github.com/juanfont/headscale/commit/5db7716be229ac5ff47a24fc0ff03e39589eed3f) Reduce the mutex size when the client closes the connection ### 📊 Changes **1 file changed** (+7 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `api.go` (+7 -6) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 02:29:14 +01:00
adam closed this issue 2025-12-29 02:29:14 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#1214