mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-20 12:37:04 -04:00
[PR #134] [CLOSED] Fix goroutine and resource leak in terminal exec timeout handling #182
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/134
Author: @Vaibhavee89
Created: 2/23/2026
Status: ❌ Closed
Base:
master← Head:fix/goroutine-leak-issue-108📝 Commits (3)
5b356dcFix goroutine and resource leak in terminal exec timeout handlingdbb4051Add comprehensive tests for goroutine leak fix42fb981fix: add explicit resp.Close() before grace period wait📊 Changes
4 files changed (+407 additions, -4 deletions)
View changed files
📝
backend/go.mod(+1 -0)📝
backend/pkg/tools/terminal.go(+17 -4)➕
backend/pkg/tools/terminal_leak_test.go(+217 -0)➕
backend/pkg/tools/terminal_load_test.go(+172 -0)📄 Description
Summary
Fixes #108
This PR addresses the goroutine and resource leak in the
getExecResult()method inbackend/pkg/tools/terminal.go. The issue occurred when command execution timed out - theio.Copygoroutine would remain blocked even after context cancellation, leading to memory bloat in long-running systems.Changes Made
donechannel with buffered error channel (errChan): The goroutine now sends theio.Copyerror result througherrChaninstead of just closing a channeldefaultExtraExecTimeout)Technical Details
The fix ensures that:
errChandefaultExtraExecTimeout(5 seconds) for the goroutine to finish cleanlyTest Plan
Impact
This fix prevents:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.