fix: prevent timer leak in GTFS retry loop#801
Open
ashnaaseth2325-oss wants to merge 1 commit intoOneBusAway:mainfrom
Open
fix: prevent timer leak in GTFS retry loop#801ashnaaseth2325-oss wants to merge 1 commit intoOneBusAway:mainfrom
ashnaaseth2325-oss wants to merge 1 commit intoOneBusAway:mainfrom
Conversation
Replace time.After with time.NewTimer in the three backoff sleeps inside InitGTFSManager so the timer is stopped immediately when the context is cancelled, instead of leaking in the runtime heap until it fires. Signed-off-by: ashnaaseth2325-oss <ashnaaseth2325@gmail.com>
Contributor
Author
|
Hello @aaronbrethorst |
Contributor
Author
|
Hi @aaronbrethorst |
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
This PR fixes a timer lifecycle issue in
InitGTFSManagerwhere retry backoff usedtime.After, which cannot be stopped on context cancellation. It replaces those calls withtime.NewTimerto ensure proper cleanup.The changes affect
internal/gtfs/gtfs_manager.go, specifically the retry sleep logic in the GTFS initialization flow.FIX
VERIFICATION
Test by starting the service with a failing GTFS endpoint so it enters the retry loop, then cancel the context (e.g., send SIGTERM) while it is sleeping. The function should exit immediately with
ctx.Err()instead of waiting for the delay. Retry behavior should remain unchanged when the context is not cancelled, with no lingering timers.