containers / containers/gvisor-tap-vsock

/stats http handler is not concurrency-safe?

Open
#16 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
435
Forks
102
Avg merge
1d 23h
Merged PRs (30d)
14

Description

`func (n *VirtualNetwork) Mux() http.Handler` has:

```
mux.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(statsAsJSON(n.networkSwitch.Sent, n.networkSwitch.Received, n.stack.Stats()))
})
```

The `Sent` and `Received` variables are modified using atomic functions, but I suspect they need to read through similar APIs for something thread-safe?

n.stack.Stats() is:
```
// Stats returns a mutable copy of the current stats.
//
// This is not generally exported via the public interface, but is available
// internally.
func (s *Stack) Stats() tcpip.Stats {
return s.stats
}
```

This does not seem to be something which is intended to be accessed safely from multiple threads?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at VirtualNetwork.Mux and the /stats handler, then read Stack.Stats and the Sent and Received access paths shown in the issue. Check how concurrent stats requests and updates are handled, and identify or run the relevant network-stack tests if available. Done means /stats can be read while counters and stack statistics change without a race or inconsistent access.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.