Skip to content

fix: propagate context into static GTFS HTTP download#536

Open
suhr25 wants to merge 3 commits intoOneBusAway:mainfrom
suhr25:fix/context-propagation-static-gtfs
Open

fix: propagate context into static GTFS HTTP download#536
suhr25 wants to merge 3 commits intoOneBusAway:mainfrom
suhr25:fix/context-propagation-static-gtfs

Conversation

@suhr25
Copy link

@suhr25 suhr25 commented Mar 2, 2026

This PR makes GTFS downloads respect context cancellation. Previously, ForceUpdate(ctx) accepted a context but the HTTP request ignored it. Changes are mainly in internal/gtfs/static.go, with small updates in gtfs_manager.go.

FIX

  • Issue: HTTP requests were created without context, so cancellation/timeouts from ForceUpdate had no effect.
  • Fix: Pass ctx through loadGTFSDatarawGtfsData and use http.NewRequestWithContext.
// BEFORE
req, err := http.NewRequest("GET", source, nil)

// AFTER
req, err := http.NewRequestWithContext(ctx, "GET", source, nil)

VERIFICATION

  • Run: go test ./...

  • Test with a slow GTFS endpoint and a short timeout:

    • Call ForceUpdate with ~500ms context
    • Before: waits ~5 minutes
    • After: exits quickly with context deadline exceeded

rawGtfsData used http.NewRequest (no context), so ForceUpdate's
caller context was never linked to the HTTP request. Switch to
http.NewRequestWithContext and thread ctx through loadGTFSData
and rawGtfsData so cancellations and deadlines take effect.

Signed-off-by: suhr25 <suhridmarwah07@gmail.com>
@suhr25
Copy link
Author

suhr25 commented Mar 2, 2026

Hi @aaronbrethorst,
Can you please take a look at this.
Thanks!

Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Suhrid — clean fix. The ForceUpdate method accepted a context but the HTTP request underneath was ignoring it entirely. Threading ctx through loadGTFSDatarawGtfsDatahttp.NewRequestWithContext is exactly the right fix, and keeping context.Background() for the startup path in InitGTFSManager is correct since there's no meaningful caller context at that point.

Critical

No critical issues.

Important

No important issues.

Fit and Finish

No fit-and-finish issues. Single commit, minimal diff, correct change.

Note

PR #513 is also modifying InitGTFSManager and loadGTFSData to accept context.Context. You'll need to fix this merge conflict before I can merge your PR.

suhr25 added 2 commits March 4, 2026 12:19
…ry logic

- InitGTFSManager now accepts context.Context and propagates it through
  loadGTFSData and buildGtfsDB instead of using context.Background()
- Preserve retry loop from main: configurable backoffs, cancellable sleeps,
  partial DB cleanup between attempts, and retry success logging
- buildGtfsDB signature updated to accept context.Context; ForceUpdate
  call site updated accordingly
- Add StartupRetries []time.Duration field to Config for configurable backoffs
- Update all InitGTFSManager call sites to pass context.Background()
Resolve conflicts keeping ctx passed through InitGTFSManager,
loadGTFSData, and BuildApplication call chains. Retain StartupRetries
field comment and retry/backoff logic from fix branch.
@suhr25
Copy link
Author

suhr25 commented Mar 4, 2026

Hi @aaronbrethorst,
As you said I have resolved the conflict.
Can you please take a look at this again.
Thanks!

@suhr25 suhr25 requested a review from aaronbrethorst March 4, 2026 13:25
Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Suhrid, thanks for resolving the merge conflict. The context propagation fix itself is still clean, and the conflict resolution correctly preserved the ctx threading through the startup retry loop in InitGTFSManager.

One small thing to fix before we can merge:

Fit and Finish

  1. Run go fmt — The merge conflict resolution introduced inconsistent struct field alignment in internal/gtfs/config.go. Lines 28–31 (Env, Verbose, EnableGTFSTidy, StartupRetries) use narrower alignment than the fields above them. Running go fmt ./... will fix this automatically.

Thanks again, and I look forward to merging this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants