Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Protocol/session.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/connect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 15 additions & 0 deletions test/protocol/cursor_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading