Ankermgmt / ankermake-m5-protocol

Ankermake M5 protocol specifications and libraries *NOT AFFILIATED WITH ANKER*
GNU General Public License v3.0
163 stars 35 forks source link

[BUG] PPPP service does not stop trying to contact the printer when the last websocket is closed #158

Open treitmayr opened 7 months ago

treitmayr commented 7 months ago

Bug Description When the ankerctl web server runs, the printer is not available, and at least one browser is connected to ankerctl, the server tries to contact the printer coninuously, as would be expected so that the PPPP badge can be updated. However, when the browser (tab) is closed, the server still tries to contact the printer via PPPP. When started as a docker service, this will result in constant write accesses to the log file.

Note: This bug is not related to the number of bugs concerning unsuccessful PPPP connections!

To Reproduce Steps to reproduce the behavior:

  1. Turn off printer
  2. Start ankerctl web server
  3. Connect with a web browser to the web server
  4. Check that the web server starts printing messages Trying connect to printer AnkerMake M5C (EUPRAKM-013657-LNCZN) over pppp using ip <IP>
  5. Close the browser (tab)
  6. The ankerctl web server will not stop printing the above message

Expected Behavior As soon as there is no websocket connection from any web browser to the PPPP websocket endpoint anymore, ankerctl should stop trying to contact the printer via PPPP.

Additional Context This issue can be observed using the master branch as well as the modified version of PR #145 and anselor:exiles.

Initial Analysis The PPPP service is implemented in a way that it is only "started" when the PPPP could be established. The ServiceManager.borrow() and ServiceManager.stream() functions called by the websocket endpoint both try to start the PPPP service without employing any timeout meachanism. Furthermore (and possibly only relevant for the PR #145 version), the PPPP websocket endpoint should check if the websocket connection is still alive inside its loop.

billyjbryant commented 7 months ago

Ankerctl does health check connections to the printer as it is an "always on" service. If the service is running, it is communicating to the printer to maintain connection so that when you load the website, it is ready.