feat: extend the request lock from extendTimeout - #4041
Open
atirna wants to merge 1 commit into
Open
Conversation
Adds an optional per-request lock prolongation to the request queue backend contract and wires it to `context.extendTimeout`, so a request that asks for more time does not have its lock expire on a locking storage backend while it is still being processed. Fixes apify#3961
B4nan
force-pushed
the
fix/extend-request-lock
branch
from
August 18, 2026 18:25
e39cd6e to
de06345
Compare
Member
|
heads up: the |
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.
Description
I added an optional per-request lock prolongation to the storage contract,
prolongRequestLock(requestId, secs), and wired it tocontext.extendTimeout, so a request that asks for more time does not have its lock expire on a locking storage backend while it is still being processed.Previously
extendTimeoutpushed the handler window, the navigation window and the internal timeout, but not the storage lock. RaisingsetExpectedRequestProcessingTimeSecsfromextendTimeoutwas tried in #3860 and reverted (the hint is process-wide, raise-only, and not retroactive), so this goes per-request instead, as proposed in #3961:RequestQueueBackend.prolongRequestLock?(requestId, secs)— optional, backends without locking leave it unimplemented; resolvesfalsewhen the lock could not be prolonged (information, not an error)RequestQueue,RequestManagerTandemandThrottlingRequestManagerforward it (the throttling one routes to the manager holding the request without consuming the in-flight marker used bymarkRequestAsHandled/reclaimRequest)context.extendTimeoutfires it best-effort: a rejection is logged at debug level, it never fails the request that asked for more timeFixes #3961
Why
On a locking storage backend (e.g. the Apify request queue) the lock is sized once from the expected processing time. A request that extends its timeout past that hint can outlive its lock, and another consumer sharing the queue may get the same request handed out while the first one is still processing it.
Verification
true/falsecases), tandem forwarding, throttling routing (marker preserved, request then marked handled in the right manager), and the crawler wiring (context.extendTimeoutprolongs the lock of the very request the handler runs for)prolongedstays empty), restoring it passes againpnpm vitest runon the four touched test files: 224 passedpnpm tsc-check-tests,pnpm lint(0 errors),pnpm format:check,pnpm api:checkall clean;docs/public-apireports regenerated