airqo-platform / airqo-platform/AirQo-api
Fix potential race condition in message consumer timeout handling
- Vorherrschende Sprache
- JavaScript
- Sterne
- 26
- Forks
- 24
- Ø Merge
- 5 Std. 36 Min.
- Gemergte PRs (30 T.)
- 81
Beschreibung
## Issue Description
The current implementation of the message consumer timeout handling in `src/auth-service/bin/start-consumer.js` has a potential issue where the timeout callback is never cleared if the consumer initialization completes after the race has been won by the timeout promise.
This can lead to misleading 'timed out' warnings in the logs and a small memory leak.
## Suggested Fix
Add a `clearTimeout` call after the race is resolved to cancel the timeout callback:
```diff
- const consumerPromise = messageConsumer();
- const timeoutPromise = new Promise((resolve) => {
- const timeoutMs = constants.MESSAGE_CONSUMER_STARTUP_TIMEOUT_MS || 10000;
- setTimeout(() => {
+ const consumerPromise = messageConsumer();
+ let timeoutId;
+ const timeoutPromise = new Promise((resolve) => {
+ const timeoutMs = constants.MESSAGE_CONSUMER_STARTUP_TIMEOUT_MS || 10000;
+ timeoutId = setTimeout(() => {
...
- }, timeoutMs);
+ }, timeoutMs);
});
- const result = await Promise.race([consumerPromise, timeoutPromise]);
+ const result = await Promise.race([consumerPromise, timeoutPromise]);
+ clearTimeout(timeoutId);
```
## References
- PR: https://github.com/airqo-platform/AirQo-api/pull/4716
- Comment: https://github.com/airqo-platform/AirQo-api/pull/4716#discussion_r2051508777
This issue was identified by CodeRabbit during code review.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.