threefoldtech / myceliumflut

0 stars 0 forks source link

macos app: add wake & sleep handler #69

Closed iwanbk closed 1 month ago

iwanbk commented 1 month ago

The ping become failed when the app put to sleep. (It is expected).

app state image

ping side image

But the ping didn't instantly recovered after the app wake up again (not expected) app state image

ping side image

The recovery time varied, sometimes almost instantly but sometimes more than 10 minutes. The long recovery was noticed when the battery is low (< 20%)

One of the quick solution is to restart the mycelium after wake up.

iwanbk commented 1 month ago

One of the quick solution is to restart the mycelium after wake up.

I have tried these things:

  1. restart mycelium from within the PacketTunnelProvider, but didn't work. Some observation:

    • Stopping the tunnel doesnt tearing down the TUN device
    • Starting the tunnel failed to get TUN device. We got errno 9 ( EBADF: Bad file descriptor)
  2. Add sleep and wake up handler to macos NSWindow

    • it still doesn't work, we don't get wake & sleep event notification
    • why we do this? the only difference with current restart is that current restart is triggered from the NSWindow, not within PacketTunnelProvider
iwanbk commented 1 month ago

i found that restarting mycelium outside the PacketTunnelProvider works perfectly. I use https://pub.dev/packages/flutter_desktop_sleep to detect wake event and do the restart.

iwanbk commented 1 month ago

I also found that the problem might be in mycelium itself because:

iwanbk commented 1 month ago

fixed at #71