[PR #5200] [MERGED] server/group: fix port leak and incorrect Listen port in TCPGroup #5167

Closed
opened 2026-05-05 14:55:58 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fatedier/frp/pull/5200
Author: @fatedier
Created: 3/5/2026
Status: Merged
Merged: 3/5/2026
Merged by: @fatedier

Base: devHead: new


📝 Commits (1)

  • 1487e1d server/group: fix port leak and incorrect Listen port in TCPGroup

📊 Changes

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

View changed files

📝 server/group/tcp.go (+2 -1)

📄 Description

Summary

Fix two bugs in TCPGroup.Listen() (server/group/tcp.go):

  • Port leak: When net.Listen fails after portManager.Acquire succeeds, the acquired port was never released, causing it to stay in usedPorts permanently until frps restart.
  • Wrong port: net.Listen used the requested port parameter instead of realPort (the actually allocated port). When port==0 (random allocation), this caused the system to listen on a different random port than what the port manager recorded.

Fix

-  tcpLn, errRet := net.Listen("tcp", net.JoinHostPort(addr, strconv.Itoa(port)))
+  tcpLn, errRet := net.Listen("tcp", net.JoinHostPort(addr, strconv.Itoa(realPort)))
   if errRet != nil {
+      tg.ctl.portManager.Release(realPort)
       err = errRet
       return
   }

Test plan

  • make build — compiles successfully
  • make test — all unit tests pass
  • make e2e — 224 passed, 0 failed, 2 skipped

🔄 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/fatedier/frp/pull/5200 **Author:** [@fatedier](https://github.com/fatedier) **Created:** 3/5/2026 **Status:** ✅ Merged **Merged:** 3/5/2026 **Merged by:** [@fatedier](https://github.com/fatedier) **Base:** `dev` ← **Head:** `new` --- ### 📝 Commits (1) - [`1487e1d`](https://github.com/fatedier/frp/commit/1487e1d167fc36418dbf3877a9ccbe81428af1e8) server/group: fix port leak and incorrect Listen port in TCPGroup ### 📊 Changes **1 file changed** (+2 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `server/group/tcp.go` (+2 -1) </details> ### 📄 Description ## Summary Fix two bugs in `TCPGroup.Listen()` (`server/group/tcp.go`): - **Port leak**: When `net.Listen` fails after `portManager.Acquire` succeeds, the acquired port was never released, causing it to stay in `usedPorts` permanently until frps restart. - **Wrong port**: `net.Listen` used the requested `port` parameter instead of `realPort` (the actually allocated port). When `port==0` (random allocation), this caused the system to listen on a different random port than what the port manager recorded. ## Fix ```diff - tcpLn, errRet := net.Listen("tcp", net.JoinHostPort(addr, strconv.Itoa(port))) + tcpLn, errRet := net.Listen("tcp", net.JoinHostPort(addr, strconv.Itoa(realPort))) if errRet != nil { + tg.ctl.portManager.Release(realPort) err = errRet return } ``` ## Test plan - [x] `make build` — compiles successfully - [x] `make test` — all unit tests pass - [x] `make e2e` — 224 passed, 0 failed, 2 skipped --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 14:55:58 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#5167
No description provided.