Skip to content

datastore/github.go: webhook re-parsed in a nested loop and unbounded goroutine fan-out against the GitHub API #271

Description

@whywaita

Problem

Two scalability issues in pkg/datastore/github.go.

1. O(pending runs × queued jobs) with JSON parsing in the inner loop

In the pending-run detection (pkg/datastore/github.go:58-78), for every pending workflow run the code iterates all queued jobs and calls github.ParseWebHook (full JSON parse of the stored webhook payload) per pair. With N runs and M jobs that is N×M parses per tick.

2. One goroutine per repository, no concurrency limit

pkg/datastore/github.go:97-130 spawns a goroutine per recently-active repository to call the GitHub API, with no semaphore or errgroup.SetLimit. On installations with many repositories this bursts requests and eats the rate limit budget that the starter/runner paths also depend on.

Suggested fix

  • Parse each queued job's payload once, collect run IDs into a map[int64]struct{}, then check pending runs against the set (O(N+M)).
  • Use errgroup.Group with SetLimit(n) (or a semaphore.Weighted) for the per-repository fan-out.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions