Skip to content

feat: Make server API read timeout configurable#1

Draft
jacek-kupczyk-wenovate wants to merge 1 commit into
mainfrom
feat/add_configurable_read_timeout
Draft

feat: Make server API read timeout configurable#1
jacek-kupczyk-wenovate wants to merge 1 commit into
mainfrom
feat/add_configurable_read_timeout

Conversation

@jacek-kupczyk-wenovate

@jacek-kupczyk-wenovate jacek-kupczyk-wenovate commented Jun 19, 2026

Copy link
Copy Markdown

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.

2026-06-17T12:56:25.9123226Z Caused by: ExecutionException: com.scanoss.exceptions.ScanApiException: SCANOSS API request timed out for https://example.com/scan/direct
2026-06-17T12:56:25.9124504Z     Caused by: ScanApiException: SCANOSS API request timed out for https://example.com/scan/direct
2026-06-17T12:56:25.9125324Z         Caused by: SocketTimeoutException: timeout
2026-06-17T12:56:25.9125950Z             Caused by: SocketException: Socket closed

Changes

  • ScanApi - added a readTimeout field (default Duration.ZERO). The OkHttp client is now always built with an explicit readTimeout so OkHttp's built-in 10-second default is never silently inherited.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_TIMEOUT and exposes readTimeout on Scanner and ScanApi builders.
  • Configures OkHttp with readTimeout(...) in addition to the existing callTimeout(...).
  • Adds --read-timeout CLI 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;

@jacek-kupczyk-wenovate jacek-kupczyk-wenovate changed the title feat: Add configurable read timeout feat: Make server API read timeout configurable Jun 19, 2026
@jacek-kupczyk-wenovate jacek-kupczyk-wenovate force-pushed the feat/add_configurable_read_timeout branch 2 times, most recently from 055ddad to 5db8466 Compare June 22, 2026 19:55
@jacek-kupczyk-wenovate jacek-kupczyk-wenovate force-pushed the feat/add_configurable_read_timeout branch from 5db8466 to 2ffba3f Compare June 22, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants