mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-08-30 13:21:49 +00:00
usbip: close pre-promotion conns on shutdown
Tie accepted conns to s.ctx via closeConnOnContextDone and wait for dispatch goroutines in Close so handshake reads/writes can no longer leak goroutines or fds past service shutdown.
This commit is contained in:
parent
b9cf48a827
commit
74140d3c67
2 changed files with 7 additions and 0 deletions
|
|
@ -36,6 +36,8 @@ type ServerService struct {
|
|||
sessions map[DataSession]struct{}
|
||||
sessionsClosed bool
|
||||
sessionsWG sync.WaitGroup
|
||||
|
||||
pendingConnsWG sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewServerService(ctx context.Context, logger log.ContextLogger, tag string, options option.USBIPServerServiceOptions) (adapter.Service, error) {
|
||||
|
|
@ -126,6 +128,7 @@ func (s *ServerService) Close() error {
|
|||
for _, session := range sessions {
|
||||
_ = session.Close()
|
||||
}
|
||||
s.pendingConnsWG.Wait()
|
||||
s.sessionsWG.Wait()
|
||||
|
||||
s.reconcileAccess.Lock()
|
||||
|
|
|
|||
|
|
@ -34,11 +34,15 @@ func (s *ServerService) acceptLoop(ln net.Listener) {
|
|||
s.logger.Error("accept: ", err)
|
||||
return
|
||||
}
|
||||
s.pendingConnsWG.Add(1)
|
||||
go s.dispatchConn(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerService) dispatchConn(conn net.Conn) {
|
||||
defer s.pendingConnsWG.Done()
|
||||
cancelClose := closeConnOnContextDone(s.ctx, conn)
|
||||
defer cancelClose()
|
||||
var prefix [controlPrefaceSize]byte
|
||||
_, err := io.ReadFull(conn, prefix[:])
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue