Skip to content

Commit 68746bd

Browse files
committed
fix hang on exit
1 parent 51b383f commit 68746bd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

udp/udp_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,13 @@ func (u *StdConn) getMemInfo(meminfo *[unix.SK_MEMINFO_VARS]uint32) error {
13541354
}
13551355

13561356
func (u *StdConn) Close() error {
1357+
// Attempt to unblock any outstanding sendmsg/sendmmsg calls so the shard
1358+
// workers can drain promptly during shutdown. Ignoring errors here is fine
1359+
// because some platforms/kernels may not support shutdown on UDP sockets.
1360+
if err := unix.Shutdown(u.sysFd, unix.SHUT_WR); err != nil && err != unix.ENOTCONN && err != unix.EINVAL && err != unix.EBADF {
1361+
u.l.WithError(err).Debug("Failed to shutdown UDP socket for close")
1362+
}
1363+
13571364
var flushErr error
13581365
for _, shard := range u.sendShards {
13591366
if shard == nil {

0 commit comments

Comments
 (0)