[PR #1093] [MERGED] fix goroutine leak #1871

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

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/1093
Author: @ma6174
Created: 12/25/2022
Status: Merged
Merged: 12/25/2022
Merged by: @juanfont

Base: mainHead: leak


📝 Commits (1)

📊 Changes

1 file changed (+10 additions, -2 deletions)

View changed files

📝 protocol_common_poll.go (+10 -2)

📄 Description

Prometheus goroutine count:

image

After some debugging, I found the goroutine leak at keepAliveChan, if client is disconnected, server goroutine may block at write keepAliveChan, with a select and check context fix this issue.

3e9ee816f9/protocol_common_poll.go (L667)

goroutine profile: total 153
86 @ 0x43cab6 0x405ecc 0x405a7d 0xfe26ee 0x46dda1
#	0xfe26ed	github.com/juanfont/headscale.(*Headscale).scheduledPollWorker+0x56d	github.com/juanfont/headscale/protocol_common_poll.go:667
  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

🔄 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/1093 **Author:** [@ma6174](https://github.com/ma6174) **Created:** 12/25/2022 **Status:** ✅ Merged **Merged:** 12/25/2022 **Merged by:** [@juanfont](https://github.com/juanfont) **Base:** `main` ← **Head:** `leak` --- ### 📝 Commits (1) - [`b3fa318`](https://github.com/juanfont/headscale/commit/b3fa3185648399a4a1878ee0d23a53dc6760afca) fix goroutine leak ### 📊 Changes **1 file changed** (+10 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `protocol_common_poll.go` (+10 -2) </details> ### 📄 Description Prometheus goroutine count: <img width="872" alt="image" src="https://user-images.githubusercontent.com/1449133/209466427-11868d1a-ac27-4ed9-8564-1b7710477e4d.png"> After some debugging, I found the goroutine leak at `keepAliveChan`, if client is disconnected, server goroutine may block at write `keepAliveChan`, with a select and check context fix this issue. https://github.com/juanfont/headscale/blob/3e9ee816f9394f2f40bede40797695cf02ac064e/protocol_common_poll.go#L667 ``` goroutine profile: total 153 86 @ 0x43cab6 0x405ecc 0x405a7d 0xfe26ee 0x46dda1 # 0xfe26ed github.com/juanfont/headscale.(*Headscale).scheduledPollWorker+0x56d github.com/juanfont/headscale/protocol_common_poll.go:667 ``` <!-- Please tick if the following things apply. You… --> - [ ] read the [CONTRIBUTING guidelines](README.md#contributing) - [ ] raised a GitHub issue or discussed it on the projects chat beforehand - [ ] added unit tests - [ ] added integration tests - [ ] updated documentation if needed - [ ] updated CHANGELOG.md <!-- If applicable, please reference the issue using `Fixes #XXX` and add tests to cover your new code. --> --- <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:32:03 +01:00
adam closed this issue 2025-12-29 02:32:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#1871