fix(backend): handle Gitea ERR_STREAM_PREMATURE_CLOSE during sync#1405
Conversation
Force identity encoding / connection close in the Gitea API fetch to avoid cross-fetch failing to read the response body, and guard against null repo data so a failed fetch no longer crashes on repo.full_name. Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR changes Gitea sync to force identity-encoded fetches, reject invalid repository responses, and skip null repository entries. It also adds a changelog entry for the fix. ChangesGitea sync reliability fix
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant SyncJob
participant giteaApi
participant customFetch
participant GiteaServer
SyncJob->>giteaApi: repoGet(org, repo)
giteaApi->>customFetch: fetch request
customFetch->>GiteaServer: HTTP request (Accept-Encoding identity, Connection close)
GiteaServer-->>customFetch: response body
customFetch-->>giteaApi: response
giteaApi-->>SyncJob: HttpResponse(data, error)
alt error present or data missing
SyncJob->>SyncJob: throw error
else valid data
SyncJob->>SyncJob: filter null/undefined repos, log warning
SyncJob->>SyncJob: continue aggregation
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
…rr_stream_premature_close-75d2
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/backend/src/gitea.ts`:
- Around line 230-233: The paginated repo listing paths in
getReposOwnedByUsers() and getReposForOrgs() are missing the same
empty/error-response guard used elsewhere, so a premature-close from paginate()
can bubble up as an opaque failure. Update the pagination handling in these
functions in gitea.ts to explicitly check for response.error or missing
response.data after each page fetch, and throw a clear error with the relevant
repo/org context before mapping or accumulating results.
- Around line 15-29: The custom fetch wrapper in gitea.ts is forcing Connection:
close for every request, which breaks keep-alive reuse during paginated
org/repo/user syncs. Update customFetch to apply this workaround only for
affected Gitea hosts or error-prone cases, or switch to a keep-alive agent while
still preserving the Accept-Encoding identity workaround. Keep the change
localized to customFetch so the rest of the Gitea request flow continues using
normal connection reuse.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 128bae05-8209-4db2-b9bc-93dcd60bd6ba
📒 Files selected for processing (2)
CHANGELOG.mdpackages/backend/src/gitea.ts
…rr_stream_premature_close-75d2
Fixes SOU-1484
Fixes #1404
Syncing repos from some self-hosted Gitea instances fails when
cross-fetchcan't read the API response body (ERR_STREAM_PREMATURE_CLOSE).repoGet()then returns{ data: null, error: {...} }, the null gets pushed into the repo list, and the sync crashes onrepo.full_name.Changes:
Accept-Encoding: identityandConnection: close, which avoids the premature close (root cause).repoGetresponse so a failed fetch surfaces as a warning/error instead of a silent null.Summary by CodeRabbit