feat: Add ping and poll pattern support for Relay Proxy compatibility #234
Bugbot Review
Bugbot Analysis Progress (3m 5s elapsed)
✅ Gathered PR context (15s)
✅ Analyzed code changes (1s)
✅ Completed bug detection — 2 potential bugs found (1m 26s)
✅ Validation and filtering completed (0s)
✅ Posted analysis results — 2 bugs reported (1m 23s)
✅ Analysis completed successfully (0s)
Final Result: Bugbot completed review and found 2 potential issues
Request ID: serverGenReqId_c16e008c-1b3b-4d86-a0b4-d5f02220ee0f
Details
Bug: Incorrect Delay Calculation Neglects Elapsed Time
Incorrect delay calculation: The max() function compares (_pollingInterval.inMilliseconds - timeSincePoll.inMilliseconds) with _pollingInterval.inMilliseconds. Since timeSincePoll is always positive (time elapsed during the poll), the first argument will always be less than the second, so max() will always return _pollingInterval.inMilliseconds. This means the delay will always be the full polling interval, completely ignoring the time already spent polling. The correct logic should use max(0, _pollingInterval.inMilliseconds - timeSincePoll.inMilliseconds) to ensure the delay is never negative while properly accounting for elapsed time.
packages/common_client/lib/src/data_sources/polling_data_source.dart#L168-L171
Bug: Resource leak: close HTTP client on stop requested
Resource leak: The HTTP client _client is never closed when the polling data source stops. Unlike the streaming data source which properly closes _pollingClient in its stop() method (line 158 in streaming_data_source.dart), the polling data source's stop() method doesn't close the client, leading to a resource leak. The stop() method should call _client.close() to properly clean up resources.