fix: prevent excessive idle ping traffic from health monitor#620
Merged
fix: prevent excessive idle ping traffic from health monitor#620
Conversation
…key to header, add file protection
Reuse AsyncStream iterator across loop iterations instead of creating a new one each cycle, which drained buffered yields instantly causing back-to-back pings. Make stopMonitoring() await task completion to prevent orphaned monitors from pinging concurrently. Closes #618
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #618 — ConnectionHealthMonitor was sending 40-50
SELECT 1pings per second when idle instead of 1 per 30 seconds.Two bugs fixed:
AsyncStream iterator recreated every loop iteration (
ConnectionHealthMonitor.swift:113): A newmakeAsyncIterator()call each cycle drained any bufferedyield()values instantly, causing back-to-back pings with zero delay. Fixed by creating the iterator once before the loop and reusing it.Orphaned monitor tasks from non-awaited
stopMonitoring()(ConnectionHealthMonitor.swift:136):stopMonitoring()cancelled the task but didn't await its completion. WhenstartHealthMonitorwas called (on reconnect, SSH tunnel recovery), the old task could still be alive and pinging alongside the new one. Fixed by makingstopMonitoring()async and awaitingtask.value.Test plan
checkNow()still triggers an immediate single ping when called