-
Notifications
You must be signed in to change notification settings - Fork 2
Add optional timeout parameter to HTTP client #111
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
akar1ngo
wants to merge
1
commit into
DeterminateSystems:main
Choose a base branch
from
akar1ngo:timeout-setting
base: main
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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.
Critical: Client caching breaks per-call timeout customization.
The client is cached in
this.client(line 51) and reused for all subsequent calls. Once created with a specific timeout, that timeout persists for all future requests, ignoring any different timeout values passed to latergetGotcalls.For example:
getGot(undefined, 5000)creates client with 5s timeoutgetGot(undefined, 30000)reuses the same client (still 5s timeout)This defeats the purpose of the timeout parameter.
Solution: Remove the client caching or make the cache timeout-aware:
Option 1 (Recommended): Remove caching
async getGot( recordFailoverCallback?: ( incitingError: unknown, prevUrl: URL, nextUrl: URL, ) => void, timeout?: number, ): Promise<Got> { - if (this.client === undefined) { - this.client = got.extend({ + return got.extend({ timeout: { request: timeout ?? DEFAULT_TIMEOUT, }, retry: { limit: Math.max((await this.getUrlsByPreference()).length, 3), methods: ["GET", "HEAD"], }, hooks: { beforeRetry: [ async (error, retryCount) => { const prevUrl = await this.getRootUrl(); this.markCurrentHostBroken(); const nextUrl = await this.getRootUrl(); if (recordFailoverCallback !== undefined) { recordFailoverCallback(error, prevUrl, nextUrl); } actionsCore.info( `Retrying after error ${error.code}, retry #: ${retryCount}`, ); }, ], beforeRequest: [ async (options) => { // The getter always returns a URL, even though the setter accepts a string const currentUrl: URL = options.url as URL; if (this.isUrlSubjectToDynamicUrls(currentUrl)) { const newUrl: URL = new URL(currentUrl); const url: URL = await this.getRootUrl(); newUrl.host = url.host; options.url = newUrl; actionsCore.debug(`Transmuted ${currentUrl} into ${newUrl}`); } else { actionsCore.debug(`No transmutations on ${currentUrl}`); } }, ], }, }); - } - - return this.client; }Remove the
clientfield from the constructor as well:constructor( idsProjectName: string, diagnosticsSuffix: string | undefined, runtimeDiagnosticsUrl: string | undefined, ) { this.idsProjectName = idsProjectName; this.diagnosticsSuffix = diagnosticsSuffix; this.runtimeDiagnosticsUrl = runtimeDiagnosticsUrl; - this.client = undefined; }And remove the field declaration:
export class IdsHost { private idsProjectName: string; private diagnosticsSuffix?: string; private runtimeDiagnosticsUrl?: string; private prioritizedURLs?: URL[]; - private client?: Got;Option 2: Make cache timeout-aware (more complex)
Use a Map to cache clients by timeout value, but this adds complexity and may not be worth it if clients are lightweight to create.
🤖 Prompt for AI Agents