From d15aba1e612580723a1d5a638906813def387e41 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Fri, 8 Dec 2023 17:24:58 +0800 Subject: [PATCH] perf: reduce timer in write_control Signed-off-by: rfyiamcool --- conn.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/conn.go b/conn.go index e27a971..f857110 100644 --- a/conn.go +++ b/conn.go @@ -454,13 +454,18 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er } } - timer := time.NewTimer(d) select { case <-c.mu: - timer.Stop() - case <-timer.C: - return errWriteTimeout + default: + timer := time.NewTimer(d) + select { + case <-c.mu: + timer.Stop() + case <-timer.C: + return errWriteTimeout + } } + defer func() { c.mu <- struct{}{} }() c.writeErrMu.Lock()