-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
Description
In the TUI code at pkg/tui/gui/dispatch.go, there's a TODO comment on line 29 indicating that request contexts should be tracked and cancelled when new requests come in. Currently, the code on line 95 uses context.Background() which cannot be cancelled.
Impact
When users rapidly switch between views or make multiple requests, previous pending requests continue to run in the background. This can lead to:
- Unnecessary memory usage
- Wasted network bandwidth
- Potential race conditions when outdated responses arrive
Location
File: pkg/tui/gui/dispatch.go
Lines: 29 (TODO comment), 95 (context creation)
Current Code
// Line 29
// TODO: Should these keep track of the context for pending requests
// and cancel previous ones as new ones come in?
// Line 95
g, _ := errgroup.WithContext(context.Background())Suggested Fix
Implement context cancellation for pending requests:
type RequestManager struct {
cancel context.CancelFunc
mu sync.Mutex
}
func (rm *RequestManager) NewRequest(ctx context.Context) context.Context {
rm.mu.Lock()
defer rm.mu.Unlock()
// Cancel previous request
if rm.cancel != nil {
rm.cancel()
}
// Create new cancellable context
newCtx, cancel := context.WithCancel(ctx)
rm.cancel = cancel
return newCtx
}Steps to Reproduce
- Open the Doppler TUI
- Rapidly switch between different views
- Monitor network requests - you'll see multiple pending requests
Additional Context
This issue was identified during a security audit of the codebase. While not a security vulnerability, it affects resource management and user experience.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels