From 5232ef0254f4c2ef0f83d02632516f213f54c250 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 1 Aug 2023 14:32:34 -0300 Subject: [PATCH] fix: race condition in server mode (#209) This fixes a race condition, I don't fully understand why though. --- multiplex/reader.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/multiplex/reader.go b/multiplex/reader.go index 8fe0da4..67f1ad3 100644 --- a/multiplex/reader.go +++ b/multiplex/reader.go @@ -62,7 +62,7 @@ var ( type syncWriter struct { b bytes.Buffer - mu sync.RWMutex + mu sync.Mutex } // Reset implements ResetableReader. @@ -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 }