-/* $OpenBSD: rtsock.c,v 1.317 2021/05/30 21:01:27 bluhm Exp $ */
+/* $OpenBSD: rtsock.c,v 1.318 2021/06/01 14:23:34 mvs Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
soassertlocked(so);
+ /*
+ * Dying socket is disconnected by upper layer and there is
+ * no reason to send packet. Also we shouldn't reschedule
+ * timeout(9), otherwise timeout_del_barrier(9) can't help us.
+ */
+ if ((so->so_state & SS_ISCONNECTED) == 0 ||
+ (so->so_state & SS_CANTRCVMORE))
+ return;
+
/* If we are in a DESYNC state, try to send a RTM_DESYNC packet */
if ((rop->rop_flags & ROUTECB_FLAG_DESYNC) == 0)
return;