Skip to content

Commit f01629e

Browse files
rfyiamcoolAlexVulaj
authored andcommitted
perf: reduce timer in write_control
Signed-off-by: rfyiamcool <[email protected]>
1 parent 85fb2d8 commit f01629e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

conn.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,18 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
446446
}
447447
}
448448

449-
timer := time.NewTimer(d)
450449
select {
451450
case <-c.mu:
452-
timer.Stop()
453-
case <-timer.C:
454-
return errWriteTimeout
451+
default:
452+
timer := time.NewTimer(d)
453+
select {
454+
case <-c.mu:
455+
timer.Stop()
456+
case <-timer.C:
457+
return errWriteTimeout
458+
}
455459
}
460+
456461
defer func() { c.mu <- struct{}{} }()
457462

458463
c.writeErrMu.Lock()

0 commit comments

Comments
 (0)