[PR #5203] [MERGED] fix: return buffers to pool on error paths to reduce GC pressure #5170

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

📋 Pull Request Information

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

Base: devHead: new


📝 Commits (1)

  • 521724b fix: return buffers to pool on error paths to reduce GC pressure

📊 Changes

2 files changed (+3 additions, -0 deletions)

View changed files

📝 pkg/nathole/nathole.go (+2 -0)
📝 pkg/proto/udp/udp.go (+1 -0)

📄 Description

Summary

  • pkg/nathole/nathole.go: waitDetectMessage allocates a buffer via pool.GetBuf each loop iteration but never returns it on error paths (ReadFromUDP failure and DecodeMessageInto failure). Added pool.PutBuf(buf) on both paths.
  • pkg/proto/udp/udp.go: writerFn in Forwarder allocates a buffer via pool.GetBuf but never returns it when the goroutine exits. Added defer pool.PutBuf(buf).

These are sync.Pool buffer leaks — not permanent memory leaks, but they increase GC pressure and allocation rate under sustained load.

Verification

  • json.Unmarshal creates independent string copies, so returning buf to pool after DecodeMessageInto is safe (no aliasing).
  • NewUDPPacket copies buf[:n] into a new slice, so returning buf via defer in writerFn is safe.
  • No double-free paths exist in either fix.
  • Build and unit tests pass.

Test plan

  • make build passes
  • make test passes
  • Manual code review confirmed no aliasing or double-free issues
  • Codex deep analysis confirmed safety of both fixes

🔄 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/5203 **Author:** [@fatedier](https://github.com/fatedier) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/6/2026 **Merged by:** [@fatedier](https://github.com/fatedier) **Base:** `dev` ← **Head:** `new` --- ### 📝 Commits (1) - [`521724b`](https://github.com/fatedier/frp/commit/521724bab382eec61961ac092d294b7d8ed98a42) fix: return buffers to pool on error paths to reduce GC pressure ### 📊 Changes **2 files changed** (+3 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `pkg/nathole/nathole.go` (+2 -0) 📝 `pkg/proto/udp/udp.go` (+1 -0) </details> ### 📄 Description ## Summary - **pkg/nathole/nathole.go**: `waitDetectMessage` allocates a buffer via `pool.GetBuf` each loop iteration but never returns it on error paths (`ReadFromUDP` failure and `DecodeMessageInto` failure). Added `pool.PutBuf(buf)` on both paths. - **pkg/proto/udp/udp.go**: `writerFn` in `Forwarder` allocates a buffer via `pool.GetBuf` but never returns it when the goroutine exits. Added `defer pool.PutBuf(buf)`. These are `sync.Pool` buffer leaks — not permanent memory leaks, but they increase GC pressure and allocation rate under sustained load. ## Verification - `json.Unmarshal` creates independent string copies, so returning `buf` to pool after `DecodeMessageInto` is safe (no aliasing). - `NewUDPPacket` copies `buf[:n]` into a new slice, so returning `buf` via defer in `writerFn` is safe. - No double-free paths exist in either fix. - Build and unit tests pass. ## Test plan - [x] `make build` passes - [x] `make test` passes - [x] Manual code review confirmed no aliasing or double-free issues - [x] Codex deep analysis confirmed safety of both fixes --- <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:56:02 -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#5170
No description provided.