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
reviewable/pr11639/r1
Tomas Janousek 1 month ago committed by Frans de Jonge
parent cd7d3b5ef6
commit b3e125a7ce

@ -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
-- <https://technet.microsoft.com/en-us/library/ee126135#BKMK_How> for

Loading…
Cancel
Save