Skip to content

Stop the previous sensor monitor when a new one is adopted - #28

Merged
ps2 merged 1 commit into
mainfrom
fix/monitor-release-on-repair
Oct 31, 2026
Merged

ps2 merged 1 commit into
mainfrom
fix/monitor-release-on-repair

Conversation

@ps2

@ps2 ps2 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Re-pairing a sensor without relaunching Loop left the previous LibreLoopSensorMonitor running:

  • adopt(monitor:) replaced self.monitor without stopping the old one.
  • delete() set monitor = nil without calling stop().
  • A stopped monitor's notification stream ends on cancellation, and it still called its disconnect handler. The handler then stopped the current monitor and scheduled another reconnect.

Each re-pair added another live watchdog (CCCD re-arms, patch status reads) and another source of spurious disconnects. Log lines and connect requests multiplied, and readings had long gaps until Loop was relaunched.

Changes:

  • stop() drops the monitor's handlers.
  • adopt stops the monitor it replaces.
  • delete stops its monitor.
  • onDisconnect ignores a monitor that is no longer current.

Builds in a next-dev workspace, and the LibreLoop tests pass. Not yet reproduced on hardware.

Re-pairing without relaunching left the old monitor running: adopt
replaced it without stopping it, and delete dropped it without stopping
it. Its silence watchdog kept re-arming CCCDs and reading patch status,
and when its stream ended it reported a disconnect that tore down the
live monitor and scheduled another reconnect, so log lines and connect
requests multiplied with each re-pair until Loop was relaunched.

stop() now drops the monitor's handlers, adopt stops the monitor it
replaces, delete stops its monitor, and a disconnect from a monitor that
is no longer current is ignored.
@ps2
ps2 merged commit 329301a into main Oct 31, 2026
@ps2

ps2 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Tested in the iOS Simulator against libre3sim, with next-dev Loop. Scenario: Delete CGM, then Add CGM and pair the same sensor; do that twice, then have the sensor drop the link.

Without this PR With this PR
monitor reported disconnect; clearing and reconnecting for one drop 2 (consecutiveNoStreamCycles 1, then 2) 1
requesting connect for one drop 2 1
Monitors left over from deleted managers still running: patchStatus quiet …; issuing direct read every minute, and the reads time out on dead sessions stopped at delete: no patch-status reads in the 100+ s after the drop

The spurious "Replace sensor" in the original report is a separate issue (#29): an event-log entry with errorData 8 repeated in patch status while patchState is still 4. libre3sim reproduces it with POST /event {"errorData":8}. This PR doesn't change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant