-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
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:
- 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: Add message broker redundancy to authentication service #4716
- Comment: Add message broker redundancy to authentication service #4716 (comment)
This issue was identified by CodeRabbit during code review.
Metadata
Metadata
Assignees
Labels
No labels