Too many open connections with Postgres server #571

Closed
opened 2025-12-29 02:20:40 +01:00 by adam · 2 comments
Owner

Originally created by @pallabpain on GitHub (Oct 30, 2023).

Bug description

When postgres is used as the database for headscale, I have observed that it frequently opens hundreds of connections with the postgres server which sometimes leads to high CPU usage on the server. The postgres server is shared between databases for other services and hence such spike in usage affects the overall performance.

While setting up pgbouncer does mitigate the issue, it would be better if headscale limits the number of open connections.

Environment

  • OS: NA
  • Headscale version: v0.22.3
  • Tailscale version: NA
  • Headscale is behind a (reverse) proxy
  • Headscale runs in a container

To Reproduce

  1. Run headscale as a k8s pod and use postgres as the database
  2. Register a bunch of nodes with headscale
  3. netstat and grep the connections established with your postgres server
  4. Monitor it with the watch command for some time.
Originally created by @pallabpain on GitHub (Oct 30, 2023). <!-- Before posting a bug report, discuss the behaviour you are expecting with the Discord community to make sure that it is truly a bug. The issue tracker is not the place to ask for support or how to set up Headscale. Bug reports without the sufficient information will be closed. Headscale is a multinational community across the globe. Our language is English. All bug reports needs to be in English. --> ## Bug description <!-- A clear and concise description of what the bug is. Describe the expected bahavior and how it is currently different. If you are unsure if it is a bug, consider discussing it on our Discord server first. --> When `postgres` is used as the database for headscale, I have observed that it frequently opens hundreds of connections with the postgres server which sometimes leads to high CPU usage on the server. The postgres server is shared between databases for other services and hence such spike in usage affects the overall performance. While setting up pgbouncer does mitigate the issue, it would be better if headscale limits the number of open connections. ## Environment <!-- Please add relevant information about your system. For example: - Version of headscale used: v0.22.3 - Version of tailscale client: NA - OS (e.g. Linux, Mac, Cygwin, WSL, etc.) and version: NA - Kernel version: NA - The relevant config parameters you used - Log output --> - OS: NA - Headscale version: v0.22.3 - Tailscale version: NA <!-- We do not support running Headscale in a container nor behind a (reverse) proxy. If either of these are true for your environment, ask the community in Discord instead of filing a bug report. --> - [ ] Headscale is behind a (reverse) proxy - [x] Headscale runs in a container ## To Reproduce <!-- Steps to reproduce the behavior. --> 1. Run headscale as a k8s pod and use postgres as the database 2. Register a bunch of nodes with headscale 3. `netstat` and `grep` the connections established with your postgres server 4. Monitor it with the `watch` command for some time.
adam added the bug label 2025-12-29 02:20:40 +01:00
adam closed this issue 2025-12-29 02:20:40 +01:00
Author
Owner

@SuperSandro2000 commented on GitHub (Jan 24, 2024):

Most likely a side effect of that is that tailscale logins never succeed and the interface never gets populated.

@SuperSandro2000 commented on GitHub (Jan 24, 2024): Most likely a side effect of that is that tailscale logins never succeed and the interface never gets populated.
Author
Owner

@pallabpain commented on GitHub (Feb 12, 2024):

The issue has been addressed in https://github.com/juanfont/headscale/pull/1583

@pallabpain commented on GitHub (Feb 12, 2024): The issue has been addressed in https://github.com/juanfont/headscale/pull/1583
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#571