0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-22 19:34:08 +01:00

Prevent double waitgroup decrement (#10170)

* Prevent double waitgroup decrement
This commit is contained in:
zeripath 2020-02-07 09:08:09 +00:00 committed by GitHub
parent d32b65ab68
commit c512bfd09c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()
}