nightscout / cgm-remote-monitor

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

Data loss in using AndroidAPS-Nightscout, due to Nightscout boot without database connection #8239

Closed petervanrijt closed 3 months ago

petervanrijt commented 3 months ago

Describe the bug After updating to Nightscout v15.0.2 and AndroidAPS v3.2.0.0+, the AndroidAPS queue is lost when booting Nightscout without a proper database connection.

To Reproduce Steps to reproduce the behavior:

Scenario 1 - data loss I shut down Synology. I boot Synology. It automatically boots containers Nightscout and mongo database. Most of the time, Nightscout boots first, which results in an error on the page. Queued uploads in AndroidAPS are lost because AndroidAPS uploads data without being able to save in the Nightscout database.

Scenario 2 - data queued I shut down Synology. I boot Synology. It does not automatically start any Docker containers. AndroidAPS queues uploads until nightscout becomes available.

Scenario 3 - data stored using Docker workaround I shut down Synology. I boot Synology. Docker first boots mongo database, after 10 minutes it boots Nightscout. I expect the databases to boot fully within 10 minutes (I have tested this, and 10 minutes seems safe). Queued uploads in AndroidAPS are saved because Nightscout is able to connect to the database.

Expected behavior I expect Nightscout to only accept a websocket connection when it has a proper connection to the database. In addition, I expect AndroidAPS to delete data in the queue only when the upload has succeeded.

Your setup information I am currently running nightscout/cgm-remote-monitor:15.0.2 on Docker with mongo:4.4.17-rc0, all on a Synology NAS. We use AndroidAPS 3.2.0.4 to upload data for Nightscout and use websockets to upload data.

Additional context I'm working on an extensive and complete update of the Nightscout - Synology documentation. I've managed to get Nightscout up and running in Docker on a Synology by using a YML-file which I will share on updating the documentation. I have it running, just need to "find some time" to get it all down on paper.

I have solved this issue by starting Nightscout 10 minutes after the database, but this is merely a temporary solution. I would really like to see it solved properly to prevent data loss for slower booting systems 🙂.

Also see https://www.facebook.com/groups/cgminthecloud/posts/7313392092115317/

petervanrijt commented 3 months ago

After more analysis I see the error exists because of uploads from AndroidAPS. For that I have created https://github.com/nightscout/AndroidAPS/issues/3276