<!-- XE-13279 · [net/msg.go] L8: request() tidak handle context cancellation sebelum Invoke selesai — resource leak · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13279>. The page is the record; this is the same page for reading.*

XE-13279 · Bounty

# \[net/msg.go\] L8: request() tidak handle context cancellation sebelum Invoke selesai — resource leak

Closed · invalid
—
[xe#424](https://github.com/xeprotocol/xe/issues/424)
filed 2026-11-12 02:49 UTC
by wahyu20260100233-ops

Verdict
:   Invalid

Tier
:   —

Claimed
:   —

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:51 UTC

Told
:   2026-11-20 00:49 UTC

### Patches

None linked.

### History

- [557310](https://bounty.xe.network/log/557310) 2026-11-20 00:49 UTC reply.mirrored
- [557065](https://bounty.xe.network/log/557065) 2026-11-20 00:48 UTC reply.sent
- [554179](https://bounty.xe.network/log/554179) 2026-11-20 00:36 UTC github.state\_pushed
- [554172](https://bounty.xe.network/log/554172) 2026-11-20 00:36 UTC github.labels
- [553334](https://bounty.xe.network/log/553334) 2026-11-20 00:33 UTC proposal.adopted
- [553128](https://bounty.xe.network/log/553128) 2026-11-20 00:33 UTC proposal.adopted
- [553127](https://bounty.xe.network/log/553127) 2026-11-20 00:33 UTC ticket.status new → closed
- [552579](https://bounty.xe.network/log/552579) 2026-11-20 00:33 UTC proposal.adopted
- [552578](https://bounty.xe.network/log/552578) 2026-11-20 00:33 UTC ticket.facts area
- [552574](https://bounty.xe.network/log/552574) 2026-11-20 00:33 UTC proposal.adopted
- [552573](https://bounty.xe.network/log/552573) 2026-11-20 00:33 UTC ticket.facts
- [551082](https://bounty.xe.network/log/551082) 2026-11-20 00:31 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-13279) · [JSON](https://bounty.xe.network/v1/tickets/XE-13279) · [markdown](https://bounty.xe.network/XE-13279.md)

### Report

## Ringkasan

Context cancellation hanya di-handle di `select` setelah `Invoke` selesai. Kalau context cancelled sebelum `Invoke` selesai, goroutine tetap jalan sampai `Invoke` return.

## Lokasi

- File: `net/msg.go`
- Lines: 130-143

## Kode

```
func (m *Messenger) request(pid peer.ID, msgType string, payload interface{}, timeout time.Duration) (json.RawMessage, error) {
    ...
    select {
    case resp := <-respCh:
        return resp.payload, resp.err
    case <-ctx.Done():
        return nil, ctx.Err()
    case <-time.After(timeout):
        return nil, ErrTimeout
    }
}
```

## Impact

Kalau context cancelled, goroutine yang menjalankan handler tetap jalan sampai selesai. Resource leak (goroutine, memory) untuk handler yang lambat.

## Suggested Fix

```
func (m *Messenger) request(pid peer.ID, msgType string, payload interface{}, timeout time.Duration) (json.RawMessage, error) {
    ...
    ctx, cancel := context.WithTimeout(context.Background(), timeout)
    defer cancel()

    respCh := make(chan msgResponse, 1)
    go func() {
        select {
        case respCh <- m.executeHandler(pid, msgType, payload):
        case <-ctx.Done():
            // handler mungkin masih jalan, tapi kita cancel context
        }
    }()

    select {
    case resp := <-respCh:
        return resp.payload, resp.err
    case <-ctx.Done():
        return nil, ctx.Err()
    }
}
```

Atau implement cancel mechanism di dalam handler execution.

```
go func() {
    defer func() {
        if ctx.Err() != nil {
            // batalkan handler execution
        }
    }()
    respCh <- m.executeHandler(pid, msgType, payload)
}()
```

### Thread

**XE desk**team2026-11-20 00:49 UTCgithub

Thanks for the report. We read it against the code and could not confirm a bug in what it describes.

This report is closed as invalid. If we have missed something, file a new report that links
https://bounty.xe.network/XE-13279 and says what; it is read like any other.
