diff options
author | zeripath <art27@cantab.net> | 2020-02-07 09:08:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 09:08:09 +0000 |
commit | c512bfd09c97b0b8ee8e5f916e7a2ad0750301e1 (patch) | |
tree | 8f1b20cae8aebe8225f839db24d672977c8f70f9 /modules/graceful | |
parent | d32b65ab682f03963e2439b0d15a94d546ff920e (diff) | |
download | gitea-c512bfd09c97b0b8ee8e5f916e7a2ad0750301e1.tar.gz gitea-c512bfd09c97b0b8ee8e5f916e7a2ad0750301e1.zip |
Prevent double waitgroup decrement (#10170)
* Prevent double waitgroup decrement
Diffstat (limited to 'modules/graceful')
-rw-r--r-- | modules/graceful/server.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/graceful/server.go b/modules/graceful/server.go index 19ce8a866f..09be933999 100644 --- a/modules/graceful/server.go +++ b/modules/graceful/server.go @@ -12,6 +12,7 @@ import ( "os" "strings" "sync" + "sync/atomic" "syscall" "time" @@ -215,9 +216,12 @@ func (wl *wrappedListener) Accept() (net.Conn, error) { } } + closed := int32(0) + c = wrappedConn{ Conn: c, server: wl.server, + closed: &closed, } wl.server.wg.Add(1) @@ -241,12 +245,12 @@ func (wl *wrappedListener) File() (*os.File, error) { 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() } |