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)) 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"