Skip to content

Commit 4786234

Browse files
authored
Merge pull request #619 from djs55/window-write
go: avoid possible overflow of the Write window
2 parents b9de5a3 + 77dd210 commit 4786234

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

go/pkg/libproxy/multiplexed.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,14 @@ func (c *channel) Write(p []byte) (int, error) {
139139
return written, io.EOF
140140
}
141141
if c.write.size() > 0 {
142+
// Some window space is available
142143
toWrite := c.write.size()
143144
if toWrite > len(p) {
144145
toWrite = len(p)
145146
}
147+
// Advance the window before dropping the lock in case another Write() appears and sees the same available space
148+
c.write.current = c.write.current + uint64(toWrite)
149+
146150
// Don't block holding the metadata mutex.
147151
// Note this would allow concurrent calls to Write on the same channel
148152
// to conflict, but we regard that as user error.
@@ -167,7 +171,6 @@ func (c *channel) Write(p []byte) (int, error) {
167171
if err3 != nil {
168172
return written, err3
169173
}
170-
c.write.current = c.write.current + uint64(toWrite)
171174
p = p[toWrite:]
172175
written = written + toWrite
173176
continue

0 commit comments

Comments
 (0)