{"id":"XE-13279","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"424","source_url":"https://github.com/xeprotocol/xe/issues/424","reporter_id":2483,"title":"[net/msg.go] L8: request() tidak handle context cancellation sebelum Invoke selesai — resource leak","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"invalid","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"invalid","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:07.115173+00:00","updated_at":"2026-11-20T00:51:12.666289+00:00","source_created_at":"2026-11-12T02:49:15+00:00","told_at":"2026-11-20T00:49:26+00:00","status_changed_at":"2026-11-20T00:33:25.886860+00:00","url":"https://bounty.xe.network/XE-13279","body":"## Ringkasan\nContext cancellation hanya di-handle di `select` setelah `Invoke` selesai. Kalau context cancelled sebelum `Invoke` selesai, goroutine tetap jalan sampai `Invoke` return.\n\n## Lokasi\n- File: `net/msg.go`\n- Lines: 130-143\n\n## Kode\n```go\nfunc (m *Messenger) request(pid peer.ID, msgType string, payload interface{}, timeout time.Duration) (json.RawMessage, error) {\n    ...\n    select {\n    case resp := <-respCh:\n        return resp.payload, resp.err\n    case <-ctx.Done():\n        return nil, ctx.Err()\n    case <-time.After(timeout):\n        return nil, ErrTimeout\n    }\n}\n```\n\n## Impact\nKalau context cancelled, goroutine yang menjalankan handler tetap jalan sampai selesai. Resource leak (goroutine, memory) untuk handler yang lambat.\n\n## Suggested Fix\n```go\nfunc (m *Messenger) request(pid peer.ID, msgType string, payload interface{}, timeout time.Duration) (json.RawMessage, error) {\n    ...\n    ctx, cancel := context.WithTimeout(context.Background(), timeout)\n    defer cancel()\n    \n    respCh := make(chan msgResponse, 1)\n    go func() {\n        select {\n        case respCh <- m.executeHandler(pid, msgType, payload):\n        case <-ctx.Done():\n            // handler mungkin masih jalan, tapi kita cancel context\n        }\n    }()\n    \n    select {\n    case resp := <-respCh:\n        return resp.payload, resp.err\n    case <-ctx.Done():\n        return nil, ctx.Err()\n    }\n}\n```\n\nAtau implement cancel mechanism di dalam handler execution.\n```go\ngo func() {\n    defer func() {\n        if ctx.Err() != nil {\n            // batalkan handler execution\n        }\n    }()\n    respCh <- m.executeHandler(pid, msgType, payload)\n}()\n```","patch_refs":[],"thread":[{"id":13361,"source":"github","source_ref":"7026791608","author":"XE desk","team":true,"body":"Thanks for the report. We read it against the code and could not confirm a bug in what it describes.\n\nThis report is closed as invalid. If we have missed something, file a new report that links\nhttps://bounty.xe.network/XE-13279 and says what; it is read like any other.","created_at":"2026-11-20T00:49:26+00:00"}]}