-
Notifications
You must be signed in to change notification settings - Fork 226
fix(v2): validate timeoutSeconds per trigger type #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kyungseopk1m
wants to merge
3
commits into
firebase:master
Choose a base branch
from
kyungseopk1m:fix/v2-timeout-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Validate `timeoutSeconds` per v2 trigger type (540s for events, 3600s for HTTPS/callable, 1800s for task queues) so misconfigured values fail at function-definition or manifest-extraction time instead of at deploy time. (#1874) |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,31 @@ import * as logger from "../logger"; | |
|
|
||
| export { RESET_VALUE } from "../common/options"; | ||
|
|
||
| /** | ||
| * Maximum timeout in seconds for event-handling functions (e.g. Firestore, | ||
| * Realtime Database, Pub/Sub, Storage, Eventarc, alerts, scheduler). | ||
| * @internal | ||
| */ | ||
| export const MAX_EVENT_TIMEOUT_SECONDS = 540; | ||
|
|
||
| /** | ||
| * Maximum timeout in seconds for HTTPS and callable functions. | ||
| * @internal | ||
| */ | ||
| export const MAX_HTTPS_TIMEOUT_SECONDS = 3600; | ||
|
|
||
| /** | ||
| * Maximum timeout in seconds for Task Queue functions. | ||
| * @internal | ||
| */ | ||
| export const MAX_TASK_TIMEOUT_SECONDS = 1800; | ||
|
|
||
| /** | ||
| * Function category used to pick a `timeoutSeconds` upper bound. | ||
| * @internal | ||
| */ | ||
| export type TimeoutKind = "event" | "https" | "task"; | ||
|
|
||
| /** | ||
| * List of all regions supported by Cloud Functions (2nd gen). | ||
| */ | ||
|
|
@@ -334,13 +359,57 @@ export interface EventHandlerOptions extends Omit<GlobalOptions, "enforceAppChec | |
| channel?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Validate that `timeoutSeconds` (resolved with global option fallback) does | ||
| * not exceed the maximum allowed value for the given function kind. Throws a | ||
| * plain `Error` matching the v1 `assertRuntimeOptionsValid` shape so the | ||
| * problem surfaces at function-definition time instead of at deploy time. | ||
| * `Expression`, `RESET_VALUE`, and `undefined` are skipped — only literal | ||
| * numbers are checked. | ||
| * @internal | ||
| */ | ||
| export function assertTimeoutSecondsValid( | ||
| opts: GlobalOptions | EventHandlerOptions | HttpsOptions | undefined, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I don't know if we need the |
||
| kind: TimeoutKind | ||
| ): void { | ||
| const timeoutSeconds = opts?.timeoutSeconds ?? getGlobalOptions().timeoutSeconds; | ||
| if (typeof timeoutSeconds !== "number") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
| return; | ||
| } | ||
| let max: number; | ||
| let label: string; | ||
| switch (kind) { | ||
| case "https": | ||
| max = MAX_HTTPS_TIMEOUT_SECONDS; | ||
| label = "HTTPS and callable"; | ||
| break; | ||
| case "task": | ||
| max = MAX_TASK_TIMEOUT_SECONDS; | ||
| label = "task queue"; | ||
| break; | ||
| default: | ||
| max = MAX_EVENT_TIMEOUT_SECONDS; | ||
| label = "event-handling"; | ||
| break; | ||
| } | ||
| if (timeoutSeconds < 0 || timeoutSeconds > max) { | ||
| throw new Error( | ||
| `timeoutSeconds must be between 0 and ${max} for ${label} functions. Got ${timeoutSeconds}.` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Apply GlobalOptions to trigger definitions. | ||
| * @internal | ||
| */ | ||
| export function optionsToTriggerAnnotations( | ||
| opts: GlobalOptions | EventHandlerOptions | HttpsOptions | ||
| opts: GlobalOptions | EventHandlerOptions | HttpsOptions, | ||
| kind?: TimeoutKind | ||
| ): TriggerAnnotation { | ||
| if (kind !== undefined) { | ||
| assertTimeoutSecondsValid(opts, kind); | ||
| } | ||
| const annotation: TriggerAnnotation = {}; | ||
| copyIfPresent( | ||
| annotation, | ||
|
|
@@ -398,8 +467,12 @@ export function optionsToTriggerAnnotations( | |
| * @internal | ||
| */ | ||
| export function optionsToEndpoint( | ||
| opts: GlobalOptions | EventHandlerOptions | HttpsOptions | ||
| opts: GlobalOptions | EventHandlerOptions | HttpsOptions, | ||
| kind?: TimeoutKind | ||
| ): ManifestEndpoint { | ||
| if (kind !== undefined) { | ||
| assertTimeoutSecondsValid(opts, kind); | ||
| } | ||
| const endpoint: ManifestEndpoint = {}; | ||
| copyIfPresent( | ||
| endpoint, | ||
|
|
||
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we're testing some of the providers, but I think we need more direct test of the wiring across providers
a parameterized suite like "each v2 provider rejects out-of-range timeout" would be a cheap way to get coverage