feat: Make server API read timeout configurable#1
Draft
jacek-kupczyk-wenovate wants to merge 1 commit into
Draft
feat: Make server API read timeout configurable#1jacek-kupczyk-wenovate wants to merge 1 commit into
jacek-kupczyk-wenovate wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configurable HTTP read timeout that can be set via both the Java SDK (builder) and the CLI, and wires it through Scanner -> ScanApi -> OkHttpClient to control socket read behavior independently from the overall call timeout.
Changes:
- Introduces
DEFAULT_READ_TIMEOUTand exposesreadTimeoutonScannerandScanApibuilders. - Configures OkHttp with
readTimeout(...)in addition to the existingcallTimeout(...). - Adds
--read-timeoutCLI option and passes it into the scanner configuration.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/main/java/com/scanoss/ScanossConstants.java |
Adds a default read-timeout constant used by SDK/CLI defaults. |
src/main/java/com/scanoss/Scanner.java |
Adds readTimeout to the scanner configuration and forwards it into ScanApi. |
src/main/java/com/scanoss/rest/ScanApi.java |
Adds readTimeout to the API client configuration and applies it to OkHttp. |
src/main/java/com/scanoss/cli/ScanCommandLine.java |
Adds --read-timeout option and wires it into scanner construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+45
to
+48
| /** | ||
| * Default read timeout for HTTP communication (0 = no read timeout; overall call is still bounded by DEFAULT_TIMEOUT) | ||
| */ | ||
| public static final int DEFAULT_READ_TIMEOUT = 0; |
| @Builder.Default | ||
| private Duration timeout = Duration.ofSeconds(DEFAULT_TIMEOUT); // API POST timeout | ||
| @Builder.Default | ||
| private Duration readTimeout = Duration.ofSeconds(DEFAULT_READ_TIMEOUT); // API read timeout (0 = disabled, inherits call timeout) |
Comment on lines
+105
to
+107
| OkHttpClient.Builder okBuilder = new OkHttpClient.Builder(); | ||
| okBuilder.callTimeout(this.timeout); // Set default timeout | ||
| okBuilder.callTimeout(this.timeout); // Set default call timeout | ||
| okBuilder.readTimeout(this.readTimeout != null ? this.readTimeout : Duration.ZERO); // 0 = no read timeout, relies on callTimeout |
Comment on lines
+104
to
+107
| if (okHttpClient == null) { | ||
| OkHttpClient.Builder okBuilder = new OkHttpClient.Builder(); | ||
| okBuilder.callTimeout(this.timeout); // Set default timeout | ||
| okBuilder.callTimeout(this.timeout); // Set default call timeout | ||
| okBuilder.readTimeout(this.readTimeout != null ? this.readTimeout : Duration.ZERO); // 0 = no read timeout, relies on callTimeout |
Comment on lines
202
to
207
| scanner = Scanner.builder().skipSnippets(skipSnippets).allFolders(allFolders).allExtensions(allExtensions) | ||
| .hiddenFilesFolders(allHidden).numThreads(numThreads).url(apiUrl).apiKey(apiKey) | ||
| .retryLimit(retryLimit).timeout(Duration.ofSeconds(timeoutLimit)).scanFlags(scanFlags) | ||
| .retryLimit(retryLimit).timeout(Duration.ofSeconds(timeoutLimit)).readTimeout(Duration.ofSeconds(readTimeoutLimit)).scanFlags(scanFlags) | ||
| .snippetLimit(snippetLimit).customCert(caCertPem).proxy(proxy).hpsm(enableHpsm) | ||
| .settings(settings).obfuscate(obfuscate) | ||
| .build(); |
Comment on lines
+88
to
+90
| @picocli.CommandLine.Option(names = {"--read-timeout"}, description = "Read timeout (in seconds) for API communication (optional - default " + DEFAULT_READ_TIMEOUT + ", 0 = disabled)") | ||
| private int readTimeoutLimit = DEFAULT_READ_TIMEOUT; | ||
|
|
055ddad to
5db8466
Compare
5db8466 to
2ffba3f
Compare
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.
Problem
OkHttp's default read timeout is 10 seconds. When scanning against a self-hosted SCANOSS instance, this limit can be hit when the server takes longer than 10 seconds to produce a response - for example when processing large files. Scans would time out even though the overall call timeout had not been reached, causing unexpected scan failures.
Changes