Skip to content

Commit

Permalink
Make Shutdown blocking to ensure outstanding requests processing comp…
Browse files Browse the repository at this point in the history
…letion
  • Loading branch information
pin committed Oct 28, 2023
1 parent c10edb1 commit 4baa433
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,16 @@ func (s *Server) processRequest() error {

// Shutdown make server stop listening for new requests, allows
// server to finish outstanding transfers and stops server.
// Shutdown blocks until all outstanding requests are processed or timed out.
// Calling Shutdown from the handler or hook might cause deadlock.
func (s *Server) Shutdown() {
if !s.singlePort {
s.Lock()
s.conn.Close()
s.Unlock()
}
s.cancelFn()
s.wg.Wait()
}

func (s *Server) handlePacket(localAddr net.IP, remoteAddr *net.UDPAddr, buffer []byte, n, maxBlockLen int, listener chan []byte) error {
Expand Down

0 comments on commit 4baa433

Please sign in to comment.