fix(hono): change syncFacilitatorOnStart default to false for serverless compatibility#2219
Closed
lau90eth wants to merge 1 commit into
Closed
fix(hono): change syncFacilitatorOnStart default to false for serverless compatibility#2219lau90eth wants to merge 1 commit into
lau90eth wants to merge 1 commit into
Conversation
…ess compatibility Fixes x402-foundation#2157 The previous default of true caused cold-start timeouts on serverless/edge environments (Cloudflare Workers, AWS Lambda) because paymentMiddleware() would block the first request while fetching facilitator support data. The accepts/extensions data needed to emit a 402 is already known from route config — facilitator init is only needed at verify/settle time. Changing the default to false enables lazy initialization: the facilitator is contacted only when an actual payment needs to be verified, not on every cold start. Users who need eager initialization can still pass syncFacilitatorOnStart: true explicitly. Updated the retry test to pass syncFacilitatorOnStart: true explicitly since it tests behavior specific to that mode.
|
@lau90eth is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
Thanks for the contribution @lau90eth but this wont fix the issue, see #2157 (comment) |
Author
|
Reopened as #2221 with the proper fix as suggested — root cause was in |
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.
Fixes #2157
Problem
paymentMiddleware()hadsyncFacilitatorOnStart: trueas default, causing cold-start timeouts on serverless/edge environments (Cloudflare Workers, AWS Lambda).On every cold isolate, the middleware would block the first request while fetching facilitator support data via
getSupported(), producing 10–15s latencies that caused discovery probes (e.g. x402scan) to time out and mark routes as invalid.Root cause
The
acceptsandextensionsdata needed to emit a 402 response is already known from route configuration — facilitator initialization is only required at verify/settle time, not for the initial 402 response.Fix
Change the default to
falseto enable lazy initialization: the facilitator is contacted only when an actual payment needs to be verified, not on every cold start.Users who need eager initialization (e.g. long-running servers) can still pass
syncFacilitatorOnStart: trueexplicitly.Changes
index.ts: changed default fromtruetofalsein all 3 exported functions (paymentMiddlewareFromHTTPServer,paymentMiddleware,paymentMiddlewareFromConfig) and updated JSDocindex.test.ts: updated retry test to passsyncFacilitatorOnStart: trueexplicitly since it tests behavior specific to that modeTesting
All 36 tests pass.