hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

hs.network.ping does not always invoke didFinish

Open earwin opened this issue 1 year ago • 2 comments

Given

function qwe(o, m, s, e) print(m, s, e) end
hs.network.ping(8.8.8.8, 5, 1, 2, 'any', qwe)

and link up, I get

2023-03-10 03:02:20: didStart	nil	nil
2023-03-10 03:02:21: receivedPacket	0	nil
2023-03-10 03:02:22: receivedPacket	1	nil
2023-03-10 03:02:23: receivedPacket	2	nil
2023-03-10 03:02:24: receivedPacket	3	nil
2023-03-10 03:02:25: receivedPacket	4	nil
2023-03-10 03:02:25: didFinish	nil	nil

link down

2023-03-10 03:03:22: didStart	nil	nil
2023-03-10 03:03:23: sendPacketFailed	0	The operation couldn’t be completed. No route to host
2023-03-10 03:03:24: sendPacketFailed	1	The operation couldn’t be completed. No route to host
2023-03-10 03:03:25: sendPacketFailed	2	The operation couldn’t be completed. No route to host
2023-03-10 03:03:26: sendPacketFailed	3	The operation couldn’t be completed. No route to host
2023-03-10 03:03:27: sendPacketFailed	4	The operation couldn’t be completed. No route to host

link up-to-down

2023-03-10 03:04:11: didStart	nil	nil
2023-03-10 03:04:12: receivedPacket	0	nil
2023-03-10 03:04:13: receivedPacket	1	nil
2023-03-10 03:04:14: sendPacketFailed	2	The operation couldn’t be completed. No route to host
2023-03-10 03:04:15: sendPacketFailed	3	The operation couldn’t be completed. No route to host
2023-03-10 03:04:16: sendPacketFailed	4	The operation couldn’t be completed. No route to host

link down-to up

2023-03-10 03:05:05: didStart	nil	nil
2023-03-10 03:05:06: sendPacketFailed	0	The operation couldn’t be completed. No route to host
2023-03-10 03:05:07: sendPacketFailed	1	The operation couldn’t be completed. No route to host
2023-03-10 03:05:08: receivedPacket	2	nil
2023-03-10 03:05:09: receivedPacket	3	nil
2023-03-10 03:05:10: receivedPacket	4	nil
2023-03-10 03:05:10: didFinish	nil	nil

So~, getting didFinish seems to be conditional on receiving the last packet.

earwin avatar Sep 02 '23 20:09 earwin

My guess is we're missing if internals[self].allSent then basicPingCompletionFunction(self) end after https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/network/ping/network_ping.lua#L479

earwin avatar Sep 02 '23 21:09 earwin

And sendPayload @ https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/network/ping/network_ping.lua#L499 should be moved to after the sentCount/allSent accounting is done, otherwise the error callback is invoked before we update allSent

earwin avatar Sep 02 '23 21:09 earwin

Associated PR was merged and we released 1.0.0 yesterday, so I'm closing this.

cmsj avatar Aug 06 '24 12:08 cmsj