Skip to content

Commit

Permalink
retry tls handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubwro committed Oct 2, 2023
1 parent 92b99b3 commit db57bf5
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/connection/reconnect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@ function socket_reconnect(nc::Connection, host, port)
info_msg = next_protocol_message(sock)
info_msg isa Info || error("Expected INFO, received $info_msg")
process(nc, info_msg)
sock
@info "Server info" info_msg
# @show fetch(nc.info)
if !isnothing(info_msg.tls_required) && info_msg.tls_required
(read_stream, write_stream) = upgrade_to_tls(sock)
@info "Socket upgraded"
end
read_stream, write_stream
end

function reconnect(nc::Connection, host, port, con_msg)
@info "Trying to connect nats://$host:$port"
start_time = time()
sock = retry(socket_reconnect, delays=SOCKET_CONNECT_DELAYS)(nc::Connection, host, port)
read_stream, write_stream = retry(socket_reconnect, delays=SOCKET_CONNECT_DELAYS)(nc::Connection, host, port)
@info "Connected after $(time() - start_time) s."

read_stream = sock
write_stream = sock

info_msg = fetch(nc.info)

@info "Server info" info_msg
# @show fetch(nc.info)
if !isnothing(info_msg.tls_required) && info_msg.tls_required
(read_stream, write_stream) = upgrade_to_tls(sock)
@info "Socket upgraded"
end
send(nc, con_msg)

lock(state.lock) do; nc.status = CONNECTED end
Expand Down

0 comments on commit db57bf5

Please sign in to comment.