Skip to content

Close the session cap race under concurrent creation#319

Open
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/session-cap-reservation-race
Open

Close the session cap race under concurrent creation#319
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/session-cap-reservation-race

Conversation

@damilolaedwards

Copy link
Copy Markdown

Summary

The session limit was enforced by counting existing sessions and creating
the new one afterward, with nothing tying the two steps together. A burst
of concurrent requests could all observe room under the cap before any of
their sessions existed yet, so the cap could be overshot under load. The
docker backend's implicit new-session path (used by execute_python when no
session_id is given) had no cap check on it at all.

Adds a reservation step on SessionManager that holds a slot in memory from
the moment a creation is allowed until the attempt finishes, so concurrent
callers can no longer all pass the same stale count. Wired into both the
explicit session-create path (docker and direct backends) and the docker
backend's implicit new-session path.

Test plan

  • go test -race ./pkg/sandbox/... ./pkg/execsvc/...
  • New test reproduces the cap being overshot without the reservation and
    holds under it with the fix, run repeatedly under -race
  • go build ./..., go vet ./...

The session limit was enforced by checking the current count and then
creating the session afterward, with nothing tying the two together.
Concurrent requests could all see room under the cap before any of
their sessions existed yet, so a burst of creations could sail past
max_sessions. The docker backend's implicit new-session path used by
execute_python had no cap check on it at all.

Add a reservation step that holds a slot in memory from the moment a
creation is allowed until the attempt finishes, so concurrent callers
can no longer all pass the same stale count. Wire it into both the
explicit session-create path and the docker backend's implicit
new-session path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant