* Prevent double waitgroup decrement
Co-authored-by: zeripath <art27@cantab.net>
"os"
"strings"
"sync"
+ "sync/atomic"
"syscall"
"time"
}
}
+ closed := int32(0)
+
c = wrappedConn{
Conn: c,
server: wl.server,
+ closed: &closed,
}
wl.server.wg.Add(1)
type wrappedConn struct {
net.Conn
server *Server
+ closed *int32
}
func (w wrappedConn) Close() error {
- err := w.Conn.Close()
- if err == nil {
+ if atomic.CompareAndSwapInt32(w.closed, 0, 1) {
w.server.wg.Done()
}
- return err
+ return w.Conn.Close()
}