mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #139] [CLOSED] fix: prevent goroutine leak in terminal exec timeout handling #185
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/139
Author: @haosenwang1018
Created: 2/23/2026
Status: ❌ Closed
Base:
master← Head:fix/goroutine-leak-exec-timeout📝 Commits (1)
c12c0b1fix: prevent goroutine leak in terminal exec timeout handling📊 Changes
1 file changed (+5 additions, -2 deletions)
View changed files
📝
backend/pkg/tools/terminal.go(+5 -2)📄 Description
Problem
When
getExecResulttimes out viactx.Done(), the function returns but leaves a goroutine blocked onio.Copy(&dst, resp.Reader). The connection (resp) is only closed bydeferafter the function returns, but by that point the goroutine is already leaked —io.Copymay remain blocked even afterresp.Close()because the close races with the blocked read.Each timed-out command leaks one goroutine and its associated resources (#108).
Fix
respbefore waiting for the goroutine on timeout, which unblocksio.Copy<-done) after closing to ensure clean shutdownrespimmediately after copy completesdefer resp.Close()since both paths now close explicitlyBefore
After
Fixes #108
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.