Skip to content

Commit 0b3746d

Browse files
committed
go: net.Conn allows concurrent Write() calls
If multiple calls are blocked waiting for window space, we need to use Broadcast() to wake them all up on a window update. Signed-off-by: David Scott <[email protected]>
1 parent 3a2c79b commit 0b3746d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

go/pkg/libproxy/multiplexed.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ func (c *channel) sendWindowUpdate() error {
105105
func (c *channel) recvWindowUpdate(seq uint64) {
106106
c.m.Lock()
107107
c.write.allowed = seq
108-
c.c.Signal()
108+
// net.Conn says: Multiple goroutines may invoke methods on a Conn simultaneously.
109+
// Therefore there can be multiple goroutines blocked in Write, so when the window opens we should wake them all up.
110+
c.c.Broadcast()
109111
c.m.Unlock()
110112
}
111113

@@ -143,14 +145,10 @@ func (c *channel) Write(p []byte) (int, error) {
143145
toWrite = len(p)
144146
}
145147
// Don't block holding the metadata mutex.
146-
// Note this would allow concurrent calls to Write on the same channel
147-
// to conflict, but we regard that as user error.
148148
c.m.Unlock()
149-
150-
// need to write the header and the payload together
151149
err := c.multiplexer.send(NewData(c.ID, uint32(toWrite)), p[0:toWrite])
152-
153150
c.m.Lock()
151+
154152
if err != nil {
155153
return written, err
156154
}

0 commit comments

Comments
 (0)