mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	* Prevent double waitgroup decrement Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -12,6 +12,7 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
						"sync/atomic"
 | 
				
			||||||
	"syscall"
 | 
						"syscall"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -215,9 +216,12 @@ func (wl *wrappedListener) Accept() (net.Conn, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						closed := int32(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c = wrappedConn{
 | 
						c = wrappedConn{
 | 
				
			||||||
		Conn:   c,
 | 
							Conn:   c,
 | 
				
			||||||
		server: wl.server,
 | 
							server: wl.server,
 | 
				
			||||||
 | 
							closed: &closed,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl.server.wg.Add(1)
 | 
						wl.server.wg.Add(1)
 | 
				
			||||||
@@ -241,12 +245,12 @@ func (wl *wrappedListener) File() (*os.File, error) {
 | 
				
			|||||||
type wrappedConn struct {
 | 
					type wrappedConn struct {
 | 
				
			||||||
	net.Conn
 | 
						net.Conn
 | 
				
			||||||
	server *Server
 | 
						server *Server
 | 
				
			||||||
 | 
						closed *int32
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (w wrappedConn) Close() error {
 | 
					func (w wrappedConn) Close() error {
 | 
				
			||||||
	err := w.Conn.Close()
 | 
						if atomic.CompareAndSwapInt32(w.closed, 0, 1) {
 | 
				
			||||||
	if err == nil {
 | 
					 | 
				
			||||||
		w.server.wg.Done()
 | 
							w.server.wg.Done()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return err
 | 
						return w.Conn.Close()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user