From b3e125a7ce3947add74f079a1128bbbdcf4f1e63 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Thu, 28 Mar 2024 14:43:07 +0000 Subject: [PATCH] NetworkMgr: Fix PocketBook losing net access Doing the `isOnline` check (`socket.dns.toip("dns.msftncsi.com")`) without having internet connectivity (`!isConnected`) results in the `isOnline` check never succeeding again even if connectivity is later acquired. This is most likely caused by /etc/resolv.conf only being parsed once - https://sourceware.org/bugzilla/show_bug.cgi?id=984, an issue that was fixed in glibc 2.26 (PocketBook firmware U740.6.8.2461 has glibc 2.23). This fix works around the problem by checking if we have a default route first before even attempting to check `isOnline`. If we don't, then `isOnline` is (almost) guaranteed to fail anyway. We could alternatively check `isConnected` instead, but that only checks wireless connectivity on many platforms, and we could have internet access via USBNet instead. Checking for the default route via any interface should work reliably for both wireless and USBNet connectivity. Another alternative fix is to add a fallback nameserver to /etc/resolv.conf like we do for the Kobo platform [1]. Unfortunately, this fix would not work in the following (rather common) scenario: 1. PocketBook boots, connects to WiFi 2. KOReader starts, /etc/resolv.conf looks all right, no fallback needed 3. PocketBook goes to sleep, disconnects from WiFi, clears resolv.conf 4. PocketBook wakes up, stays disconnected 5. KOReader user does a Wikipedia lookup, networking freezes [1]: https://github.com/koreader/koreader/pull/6424/files#diff-be863601c59a2d6607af6b04b3be2392ec4494df6d25dae48250fae57b737f61R216-R224 Fixes: https://github.com/koreader/koreader/issues/10183 Related: https://github.com/koreader/koreader/issues/6421 --- frontend/ui/network/manager.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/ui/network/manager.lua b/frontend/ui/network/manager.lua index da089d411..04e8018b2 100644 --- a/frontend/ui/network/manager.lua +++ b/frontend/ui/network/manager.lua @@ -532,6 +532,12 @@ function NetworkMgr:isOnline() return true end + -- Fail early if we don't even have a default route. + -- On PocketBook devices, if the first call to socket.dns.toip(…) fails, it never succeeds again. + if not Device:getDefaultRoute() then + return false + end + local socket = require("socket") -- Microsoft uses `dns.msftncsi.com` for Windows, see -- for