DopplerHQ / DopplerHQ/cli

[BUG] TUI requests not cancelled, causing potential memory leak

Open
#522 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
396
Forks
83
Avg merge
1d 2h
Merged PRs (30d)
3

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

  1. Open the Doppler TUI
  2. Rapidly switch between different views
  3. 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/tui/gui/dispatch.go, reading the TODO around line 29 and the context.Background() use around line 95. Trace how requests are created during rapid view switches and determine where pending request cancellation belongs. Done means superseded requests are cancelled and rapid switching no longer leaves previous requests running in the background.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.