nightscout / cgm-remote-monitor

nightscout web monitor
GNU Affero General Public License v3.0
2.36k stars 71.35k forks source link

[Bug] Nightscout crashes when setting up connect_source_libre for the first time. #8209

Open billyjbryant opened 5 months ago

billyjbryant commented 5 months ago

Describe the bug When Nightscout is configured with CONNECT_SOURCE=linkup, the server crashes upon initial load of data from Libre Link Up. This is due to a bug in nightscout_connect which improperly handles data ingestion when there are no previous data points.

If last_known is null, the plugin crashes with the following error, causing a reboot loop on the container:

 /opt/app/node_modules/nightscout-connect/lib/sources/librelinkup.js:124
       var last_updated = last_known.entries;
                                     ^

 TypeError: Cannot read properties of null (reading 'entries')
     at Object.transformGlucose [as transformer] (/opt/app/node_modules/nightscout-connect/lib/sources/librelinkup.js:124:37)
     at transformService (/opt/app/node_modules/nightscout-connect/lib/machines/fetch.js:14:37)
     at Interpreter._exec (/opt/app/node_modules/xstate/lib/interpreter.js:269:63)
     at Interpreter.exec (/opt/app/node_modules/xstate/lib/interpreter.js:1026:10)
     at Interpreter.execute (/opt/app/node_modules/xstate/lib/interpreter.js:387:14)
     at Interpreter.update (/opt/app/node_modules/xstate/lib/interpreter.js:415:12)
     at /opt/app/node_modules/xstate/lib/interpreter.js:110:15
     at Scheduler.process (/opt/app/node_modules/xstate/lib/scheduler.js:69:7)
     at Scheduler.schedule (/opt/app/node_modules/xstate/lib/scheduler.js:48:10)
     at Interpreter.send (/opt/app/node_modules/xstate/lib/interpreter.js:104:23)

This issue is fixed in nightscout_connect by adding in appropriate checks to ensure that direct reference to an undefined var are not performed and thus prevents the plugin from crashing.

This does not fix the crash in Nightscout as a result of the plugin crashing.

To Reproduce Steps to reproduce the behavior:

  1. Configure the environment variables for Libre Link Up as directed here: https://github.com/nightscout/cgm-remote-monitor?tab=readme-ov-file#libre-link-up
  2. Start the Nightscout server
  3. Monitor server logs
  4. Upon retrieving data from Link Up the plugin crashes

Expected behavior Connect should retrieve the patient data from LinkUp, process it then send it to Nightscout

Screenshots N/A

Your setup information

Additional context This bug was originally posted in https://github.com/nightscout/nightscout-connect/issues/27, cross posting it here because the failure in the connect plugin causes Nightscout to crash and restart, which is indicative of an error handling issue. The connect issue is fixed in https://github.com/nightscout/nightscout-connect/pull/34

billyjbryant commented 4 months ago

Is anyone going to look at this issue and the associated fix?