Skip to content

fix(jdbc): ignore unsupported socketTimeout instead of throwing - #226

Merged
magnusp merged 1 commit into
mainfrom
fix/i196-socket-timeout
Oct 24, 2026
Merged

magnusp merged 1 commit into
mainfrom
fix/i196-socket-timeout

Conversation

@magnusp

@magnusp magnusp commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Fixes #196

Problem

LibsqlUrlParser guarded the timeout branch on connectTimeout or socketTimeout, but always read connectTimeout:

if (queryParams.containsKey("connectTimeout") || queryParams.containsKey("socketTimeout")) {
    connectTimeout = Duration.ofMillis(Long.parseLong(queryParams.get("connectTimeout")));

Long.parseLong(null) throws NumberFormatException, so
jdbc:libsql:http://localhost:8080/dev/tenant?socketTimeout=5000 failed at parse time with an unchecked exception.

Fix

Remove socketTimeout from the guard. It is now ignored like any other unknown URL parameter. It is not mapped onto the connect timeout, and the driver gains no socket-timeout support in this PR. All other precedence rules are unchanged: query connectTimeout still wins over the Properties value, which still wins over the default.

Red (test first, before the fix)

[ERROR] Tests run: 13, Failures: 0, Errors: 1, Skipped: 0
[ERROR] LibsqlUrlParserTest.testIgnoresSocketTimeoutWithoutConnectTimeout:43 » NumberFormat Cannot parse null string
java.lang.NumberFormatException: Cannot parse null string
    at com.github.magnusp.libsql.jdbc.LibsqlUrlParserTest.testIgnoresSocketTimeoutWithoutConnectTimeout(LibsqlUrlParserTest.java:43)
[ERROR] BUILD FAILURE

Command: ./mvnw -pl libsql-jdbc -am -Dtest=LibsqlUrlParserTest -Dsurefire.failIfNoSpecifiedTests=false test

Green (after the fix)

[INFO] Tests run: 13, Failures: 0, Errors: 0, Skipped: 0 -- in com.github.magnusp.libsql.jdbc.LibsqlUrlParserTest
[INFO] BUILD SUCCESS

Same command as the red run.

Lanes

  • unit — ./mvnw test — BUILD SUCCESS; libsql-jdbc 398 tests, 0 failures, 0 errors.
  • spotless — ./mvnw spotless:check — BUILD SUCCESS.
  • conformance — ./mvnw -pl libsql-conformance -am verify — BUILD SUCCESS; 272 tests, 0 failures, 0 errors, 7 skipped (against the pinned sqld image).

Tests

  • testIgnoresSocketTimeoutWithoutConnectTimeout — socketTimeout alone parses, keeps the URL, and leaves connectTimeout at the default. Fails before the fix.
  • testConnectTimeoutStillWinsAlongsideSocketTimeout — with both parameters present, connectTimeout still applies.

Existing LibsqlUrlParserTest assertions are untouched.

The timeout branch guarded on connectTimeout or socketTimeout but always
read connectTimeout, so a URL with only socketTimeout threw
NumberFormatException from Long.parseLong(null) at parse time.

Take socketTimeout out of the guard so the parameter is ignored like any
other unknown parameter. LibsqlClientConfig has no socket timeout field,
and mapping it onto the connect timeout would change behavior that callers
did not ask for.
@magnusp
magnusp merged commit 5da73e1 into main Oct 24, 2026
6 checks passed
@magnusp
magnusp deleted the fix/i196-socket-timeout branch October 24, 2026 17:41
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.

socketTimeout alone in a JDBC URL throws NumberFormatException

1 participant