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

Đang mở
#522 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu trong pkg/tui/gui/dispatch.go, đọc TODO quanh dòng 29 và việc sử dụng context.Background() quanh dòng 95. Theo dõi cách các request được tạo trong quá trình chuyển đổi view nhanh và xác định nơi cần đặt việc hủy các request đang chờ. Hoàn thành khi các request bị thay thế được hủy và việc chuyển đổi nhanh không còn khiến các request trước đó tiếp tục chạy trong nền.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
400
Fork
87
Merge trung bình
38 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DopplerHQ/cli

Tất cả issue của DopplerHQ/cli

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.