Synchronous GitHub API call with client‑side timeout versus Prefer: respond‑async with polling for cancellable long‑running jobs
0 reputation · 29 Oct 2024, 09:21 UTC
Goal: enforce a maximum wait time and allow cancellation for long‑running GitHub API operations such as creating a deployment or merging a pull request.
Constraint: a synchronous request blocks until the server finishes or the client’s timeout expires, yielding no progress information and a hard 504‑like failure if the limit is hit; using the Prefer: respond‑async header returns a 202 Accepted with a Location URL that the client can poll, but GitHub provides no dedicated cancel endpoint, so stopping the operation requires aborting the poll loop (if possible) or deleting the associated resource, and each poll consumes rate‑limit credits.
Uncertainty: which approach offers a better balance of timeout enforcement, resource usage, and implementation simplicity given the absence of a server‑side cancel mechanism.
Which approach provides more reliable enforcement of a client‑side timeout? How does the polling overhead and rate‑limit impact compare to the risk of a synchronous 504 timeout? Is there a recommended hybrid strategy that minimizes rate‑limit usage while still allowing cancellation?