From 3b2a19694b822b9c394bf02f326000c3d29e26db Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Tue, 10 Nov 2026 12:20:12 -0700 Subject: [PATCH 1/2] Test that set_timeouts! to 0 leaves no deadline armed After a command runs under 1 s read and write timeouts, lowering them to 0 and waiting 1.5 s must not fail the next command. On main it fails with TimeoutError (phase READY) and closes the connection (#257). Co-Authored-By: Claude Opus 5.5 --- test/protocol/cursor_tests.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/protocol/cursor_tests.jl b/test/protocol/cursor_tests.jl index cc2e397..54813f4 100644 --- a/test/protocol/cursor_tests.jl +++ b/test/protocol/cursor_tests.jl @@ -1102,6 +1102,21 @@ end end end +@testset "set_timeouts! to 0 leaves no deadline armed (#257)" begin + with_native(c -> begin + expect_query(c); send_ok(c, 1) + expect_query(c); send_ok(c, 1) + end) do conn + s = N.session(conn) + P.set_timeouts!(s, 1_000_000_000, 1_000_000_000) + @test DBInterface.execute(conn, "bounded").rows_affected == 0 + P.set_timeouts!(s, 0, 0) + sleep(1.5) # past the deadline the bounded command armed + @test DBInterface.execute(conn, "unbounded").rows_affected == 0 + @test isopen(conn) + end +end + @testset "escape and identifiers" begin @test N.escape_literal("a'b\"c\\d\n\r\0\x1a", false) == "a\\'b\\\"c\\\\d\\n\\r\\0\\Z" @test N.escape_literal("a'b\\c", true) == "a''b\\c" From 8f20968bc6c65bce1cf0206b6654ab87ed0ff828 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Tue, 10 Nov 2026 12:22:57 -0700 Subject: [PATCH 2/2] Clear transport deadlines in set_timeouts! A per-operation timeout of 0 arms nothing before a read or write, so after set_timeouts!(s, 0, 0) the deadline armed under the previous timeouts stayed on the transport. Once it passed, the next statement failed with TimeoutError and the connection closed. set_timeouts! now clears both transport deadlines when the session is open. connect no longer clears the establishment deadline separately, because the set_timeouts! call that follows it does. Fixes #257 Co-Authored-By: Claude Opus 5.5 --- src/Protocol/session.jl | 10 ++++++++-- src/connect.jl | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Protocol/session.jl b/src/Protocol/session.jl index 9a75bea..3d48f93 100644 --- a/src/Protocol/session.jl +++ b/src/Protocol/session.jl @@ -70,12 +70,18 @@ max_payload(s::Session) = return s.authenticated ? s.limits.max_packet : s.limit """ set_timeouts!(s, read_timeout_ns, write_timeout_ns) -Per-operation timeouts (0 = none) re-armed before every transport read and write; distinct -from the absolute deadlines a caller may set on the transport for connection establishment. +Sets the per-operation timeouts (0 = none), which are re-armed before every transport read +and write, and clears the transport's read and write deadlines. A 0 timeout arms nothing, +so without the clear the deadline from the previous timeouts (or an absolute deadline set +on the transport) would still expire. """ function set_timeouts!(s::Session, read_timeout_ns::Integer, write_timeout_ns::Integer) s.io.read_timeout_ns = Int64(read_timeout_ns) s.io.write_timeout_ns = Int64(write_timeout_ns) + if isopen(s) + set_read_deadline!(s.transport, 0) + set_write_deadline!(s.transport, 0) + end return nothing end diff --git a/src/connect.jl b/src/connect.jl index 5000a01..eab298c 100644 --- a/src/connect.jl +++ b/src/connect.jl @@ -316,8 +316,8 @@ function connect(opts::ConnectOptions) (opts.can_handle_expired_passwords && err isa P.Error && err.errno == P.ER_MUST_CHANGE_PASSWORD && s.phase == P.READY) || rethrow() false end - deadline == 0 || apply_deadline!(s.transport, Int64(0)) - # from here on `read_timeout`/`write_timeout` apply per transport operation + # clears the establishment deadline; from here on `read_timeout`/`write_timeout` + # apply per transport operation P.set_timeouts!(s, timeout_ns(opts.read_timeout), timeout_ns(opts.write_timeout)) opts.init_command === nothing || run_init_command!(s, opts) return register!(Handle(s, opts, ReapEntry(s.transport), bootstrapped, trace))