Skip to content

Commit

Permalink
fix: race condition in server mode (#209)
Browse files Browse the repository at this point in the history
This fixes a race condition, I don't fully understand why though.
  • Loading branch information
caarlos0 authored Aug 1, 2023
1 parent b05a385 commit 5232ef0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions multiplex/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var (

type syncWriter struct {
b bytes.Buffer
mu sync.RWMutex
mu sync.Mutex
}

// Reset implements ResetableReader.
Expand All @@ -74,8 +74,8 @@ func (w *syncWriter) Reset() {

// Read implements io.Reader.
func (w *syncWriter) Read(p []byte) (n int, err error) {
w.mu.RLock()
defer w.mu.RUnlock()
w.mu.Lock()
defer w.mu.Unlock()
return w.b.Read(p) //nolint: wrapcheck
}

Expand Down

0 comments on commit 5232ef0

Please sign in to comment.