Function timeout
Resolve timeout errors in Sanity Functions by adjusting the timeout duration.
When testing Sanity Functions locally, you may see a timeout error. For example:
npx sanity functions test log-event
› Error: Timeout: Function exceeded the 10-second time limit.pnpm dlx sanity functions test log-event
› Error: Timeout: Function exceeded the 10-second time limit.yarn dlx sanity functions test log-event
› Error: Timeout: Function exceeded the 10-second time limit.bunx sanity functions test log-event
› Error: Timeout: Function exceeded the 10-second time limit.By default, function execution time is set to 10 seconds, but may be configured down as low as 1 second and as high as 900 seconds (15 minutes).
You can experiment with different timeout values directly from the command line using the --timeout flag.
npx sanity functions test log-event --timeout 15pnpm dlx sanity functions test log-event --timeout 15yarn dlx sanity functions test log-event --timeout 15bunx sanity functions test log-event --timeout 15This increases the timeout value to 15 seconds.
Note: Your functions will likely run faster locally than in the cloud. Today's modern machines far outpace the capabilities of cloud runners. So expect to add a bit of padding in your timeout value to compensate.
Once you establish an appropriate timeout value, update your blueprint file.
import { defineBlueprint, defineDocumentFunction } from "@sanity/blueprints"
export default defineBlueprint({
resources: [
defineDocumentFunction({
name: "log-event",
timeout: 15, // Add your new timeout value
}),
],
})Now the next time you test your function locally it will read the new timeout value from the blueprint.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?