Explorar o código

fix hang on exit

Ryan Huber hai 11 meses
pai
achega
68746bd907
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  1. 7 0
      udp/udp_linux.go

+ 7 - 0
udp/udp_linux.go

@@ -1354,6 +1354,13 @@ func (u *StdConn) getMemInfo(meminfo *[unix.SK_MEMINFO_VARS]uint32) error {
 }
 
 func (u *StdConn) Close() error {
+	// Attempt to unblock any outstanding sendmsg/sendmmsg calls so the shard
+	// workers can drain promptly during shutdown. Ignoring errors here is fine
+	// because some platforms/kernels may not support shutdown on UDP sockets.
+	if err := unix.Shutdown(u.sysFd, unix.SHUT_WR); err != nil && err != unix.ENOTCONN && err != unix.EINVAL && err != unix.EBADF {
+		u.l.WithError(err).Debug("Failed to shutdown UDP socket for close")
+	}
+
 	var flushErr error
 	for _, shard := range u.sendShards {
 		if shard == nil {