Skip to content

Commit

Permalink
fix: Write panic when conn Close (cloudwego#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hchenn committed Dec 14, 2021
1 parent 985eb36 commit 1344445
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion connection_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,15 @@ func (c *connection) Read(p []byte) (n int, err error) {

// Write will Flush soon.
func (c *connection) Write(p []byte) (n int, err error) {
if !c.lock(flushing) {
return 0, Exception(ErrConnClosed, "when write")
}
defer c.unlock(flushing)

dst, _ := c.outputBuffer.Malloc(len(p))
n = copy(dst, p)
err = c.Flush()
c.outputBuffer.Flush()
err = c.flush()
return n, err
}

Expand Down

0 comments on commit 1344445

Please sign in to comment.