Skip to content

Fix data race in Kubernetes StreamSession#61807

Merged
rosstimothy merged 1 commit intomasterfrom
tross/kube_stream_race
Nov 26, 2025
Merged

Fix data race in Kubernetes StreamSession#61807
rosstimothy merged 1 commit intomasterfrom
tross/kube_stream_race

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy commented Nov 26, 2025

The websocket used to communicate with Kubernetes was proctected by a mutex to prevent data races from concurrent writes. The mutex was however not being acquired when closing the session which could lead to data races since handling of various aspects of an interactive session are done in multiple goroutines.

All existing direct calls to WriteMessage were replaced with the new (SessionStream) write function which serializes all writes as intended by acquiring the writeSync mutex.

(SessionStream) Close was also reorganized to reduce indentation and return any errors that may be returned from closing the websocket.

SessionStream.closed has been updated to atomic.Bool instead of an int32 that was accessed via the atomic.Int32 APIs.

changelog: Prevent data races when terminating interactive Kubernetes sessions

The websocket used to communicate with Kubernetes was proctected
by a mutex to prevent data races from concurrent writes. The mutex
was however not being acquired when closing the session which
could lead to data races since handling of various aspects of an
interactive session are done in multiple goroutines.

All existing direct calls to `WriteMessage` were replaced with
the new `(SessionStream) write` function which serializes all
writes as intended by acquiring the `writeSync` mutex.

`(SessionStream) Close` was also reorganized to reduce indentation
and return any errors that may be returned from closing the websocket.

`SessionStream.closed` has been updated to atomic.Bool instead of an
int32 that was accessed via the atomic.Int32 APIs.
@rosstimothy rosstimothy added this pull request to the merge queue Nov 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 26, 2025
@rosstimothy rosstimothy added this pull request to the merge queue Nov 26, 2025
Merged via the queue into master with commit 29043c5 Nov 26, 2025
50 checks passed
@rosstimothy rosstimothy deleted the tross/kube_stream_race branch November 26, 2025 18:30
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@rosstimothy See the table below for backport results.

Branch Result
branch/v17 Failed
branch/v18 Create PR

rosstimothy added a commit that referenced this pull request Nov 26, 2025
The websocket used to communicate with Kubernetes was proctected
by a mutex to prevent data races from concurrent writes. The mutex
was however not being acquired when closing the session which
could lead to data races since handling of various aspects of an
interactive session are done in multiple goroutines.

All existing direct calls to `WriteMessage` were replaced with
the new `(SessionStream) write` function which serializes all
writes as intended by acquiring the `writeSync` mutex.

`(SessionStream) Close` was also reorganized to reduce indentation
and return any errors that may be returned from closing the websocket.

`SessionStream.closed` has been updated to atomic.Bool instead of an
int32 that was accessed via the atomic.Int32 APIs.
cthach pushed a commit that referenced this pull request Dec 1, 2025
The websocket used to communicate with Kubernetes was proctected
by a mutex to prevent data races from concurrent writes. The mutex
was however not being acquired when closing the session which
could lead to data races since handling of various aspects of an
interactive session are done in multiple goroutines.

All existing direct calls to `WriteMessage` were replaced with
the new `(SessionStream) write` function which serializes all
writes as intended by acquiring the `writeSync` mutex.

`(SessionStream) Close` was also reorganized to reduce indentation
and return any errors that may be returned from closing the websocket.

`SessionStream.closed` has been updated to atomic.Bool instead of an
int32 that was accessed via the atomic.Int32 APIs.
github-merge-queue bot pushed a commit that referenced this pull request Dec 4, 2025
The websocket used to communicate with Kubernetes was proctected
by a mutex to prevent data races from concurrent writes. The mutex
was however not being acquired when closing the session which
could lead to data races since handling of various aspects of an
interactive session are done in multiple goroutines.

All existing direct calls to `WriteMessage` were replaced with
the new `(SessionStream) write` function which serializes all
writes as intended by acquiring the `writeSync` mutex.

`(SessionStream) Close` was also reorganized to reduce indentation
and return any errors that may be returned from closing the websocket.

`SessionStream.closed` has been updated to atomic.Bool instead of an
int32 that was accessed via the atomic.Int32 APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants