Skip to content

fix: guard decryptors map with RWMutex to prevent data race - #9

Merged
topi314 merged 1 commit into
disgoorg:masterfrom
sealbro:fix/decryptors-race-condition
Jun 19, 2026
Merged

topi314 merged 1 commit into
disgoorg:masterfrom
sealbro:fix/decryptors-race-condition

Conversation

@sealbro

@sealbro sealbro commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fix data race on session decryptors map

Problem

The session.decryptors map (golibdave/golibdave.go) was accessed concurrently
without synchronization:

  • The audio path (Decrypt, MaxDecryptedFrameSize) reads from the map on
    per-frame decode goroutines.
  • The gateway-event path (AddUser, RemoveUser) mutates the map when users
    join or leave the voice channel.

A read on the audio goroutine racing with a write on the event goroutine is a
data race on a Go map, which can panic ("concurrent map read and map write") or
corrupt the map.

Fix

Guard the decryptors map with a sync.RWMutex

@topi314 topi314 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you ran into this

@topi314

topi314 commented Jun 19, 2026

Copy link
Copy Markdown
Member

I would generally recommend to use https://github.com/thomas-vilte/dave-go
since it doesnt require cgo

@topi314
topi314 merged commit 3988b16 into disgoorg:master Jun 19, 2026
5 checks passed
@sealbro

sealbro commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Yep, faced it in integration tests with -race flag.
thanks will check dave-go 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants