From 9d0969db2be1bff624a641158544db687f3d2427 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 5 Apr 2020 14:57:05 -0500 Subject: [PATCH] prevent a hypothetical block on link message sending --- src/yggdrasil/link.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/link.go b/src/yggdrasil/link.go index 1501799..7898628 100644 --- a/src/yggdrasil/link.go +++ b/src/yggdrasil/link.go @@ -229,10 +229,18 @@ func (intf *linkInterface) handler() error { intf.peer.Act(nil, intf.peer._removeSelf) }() intf.peer.out = func(msgs [][]byte) { - intf.writer.sendFrom(intf.peer, msgs, false) + // nil to prevent it from blocking if the link is somehow frozen + // this is safe because another packet won't be sent until the link notifies + // the peer that it's ready for one + intf.writer.sendFrom(nil, msgs, false) } intf.peer.linkOut = func(bs []byte) { - intf.writer.sendFrom(intf.peer, [][]byte{bs}, true) + // nil to prevent it from blocking if the link is somehow frozen + // FIXME this is hypothetically not safe, the peer shouldn't be sending + // additional packets until this one finishes, otherwise this could leak + // memory if writing happens slower than link packets are generated... + // that seems unlikely, so it's a lesser evil than deadlocking for now + intf.writer.sendFrom(nil, [][]byte{bs}, true) } themAddr := address.AddrForNodeID(crypto.GetNodeID(&intf.info.box)) themAddrString := net.IP(themAddr[:]).String()