What is a Watchdog and how does it work?
First, let's turn to the online encyclopedia:
A watchdog timer (WDT, or simply a watchdog), sometimes called a computer operating properly timer (COP timer), is an electronic or software timer that is used to detect and recover from computer malfunctions.[1] Watchdog timers are widely used in computers to facilitate automatic correction of temporary hardware faults, and to prevent errant or malevolent software from disrupting system operation.
[...]
Microcontrollers often include an integrated, on-chip watchdog. In other computers the watchdog may reside in a nearby chip that connects directly to the CPU, or it may be located on an external expansion card in the computer's chassis.Similar timers are found in the electronic circuits of the vast majority of embedded electronics, including Keenetic routers. Their purpose is to prevent such a hang-up, from which recovery would only be possible with physical access to the device. This is based on the assumption that the router may be installed in a location where you cannot easily access it to turn it off and on at any given moment.
Essentially, a watchdog timer can be thought of as a neighbour sitting next to you in class who periodically asks questions to make sure you are not asleep. If the neighbour does not receive an answer for some time, he starts nudging you on the side to wake you up.
You could ask yourself questions in your mind, trying to keep yourself awake. Then it would be a 'software' watchdog timer. But there are serious reasons to believe that if, after asking yourself another question, you fall asleep without answering, you will not be able to wake yourself up at the last moment either. Therefore, a watchdog timer is, as a rule, a separate component, external to the controlled system, as in the case of a neighbour. And if a neighbour in a lecture is an unreliable watchdog timer because he himself can fall asleep, then hardware implementations of such timers are made much more reliable (due to their simplicity) than the controlled system.
Returning to Keenetic, the watchdog timer in them is part of the SoC (processor) microchip. It is present in all MediaTek chipsets we use and is thoroughly patched by our developers to work specifically at the kernel level (the chipmaker's reference watchdogs can be user-space and, under high load, give false positives due to low priority). It constantly counts down from a specific number to zero. As soon as it reaches zero, it immediately performs a hardware reboot of the processor. The router's firmware attempts to prevent the timer from counting down to zero by periodically giving it a new reference point. Thus, with some assumptions, it can be argued that if the firmware freezes, it stops providing the timer with a new reference point, reaches zero, and the entire system reboots.
The assumptions are necessary because the router's software, like your inner world while sitting in a lecture, is a very complex system consisting of many components. And if, for example, you stop taking notes from the lecturer but continue to answer your neighbour, your neighbour does not consider you to be asleep. Similarly, the watchdog timer does not consider the router to be frozen if, for example, its DHCP client is in a frozen state. This is extremely unlikely, but still. Only the firmware kernel, which is responsible for the system's basic functions, interacts with the timer. These include traffic routing and Wi-Fi.
So we can say with confidence that if, by some miracle, you manage to put the router into a state where the kernel is unable to reset the watchdog timer counter (which also means that the router is unable to perform its primary tasks), it will exit this state by rebooting (the time interval is no more than 15 seconds from freezing to rebooting). And if you find that the router is completely frozen and does not respond to anything except powering off, then unfortunately, we are more inclined to suspect that it is broken hardware.
In all other cases, we consider it unnecessary to reboot the Keenetic routers, as some routers from other manufacturers do. This is because we are so confident in our code (and its test coverage) that we can say with certainty: if you have lost your Internet connection, it does not mean that all the firmware components have collapsed like a house of cards. It simply means that you need to re-establish your connection to your ISP. In extreme cases, you may need to restart the USB modem through which you access the Internet. The Ping Checker component is responsible for all of this.