Skip to content

Commit

Permalink
Ensure channel is destroyed/freed on on_shutdown callback
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Oct 7, 2024
1 parent 73ec6d5 commit 6a43d8a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/sockets/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function c_increment_read_window_task(channel_task, arg, status)
if status == Int(AWS_TASK_STATUS_RUN_READY)
socket.window_size += arg.increment
slotobj = unsafe_load(socket.slot)
# TODO: check return value of aws_channel_slot_increment_read_window
aws_channel_slot_increment_read_window(socket.slot, arg.increment)
put!(socket.ch, :read_window_incremented)
socket.debug && @info "[$(_id(socket))]: c_increment_read_window_task: incremented read window by $(arg.increment) bytes"
Expand Down Expand Up @@ -268,14 +269,13 @@ end
const SETUP_CALLBACK = Ref{Ptr{Cvoid}}(C_NULL)

function c_shutdown_callback(bootstrap, error_code, channel, socket)
GC.@preserve socket begin
socket.debug && @warn "c_shutdown_callback"
close(socket.ch)
close(socket.readbuf)
close(socket.writebuf)
socket.channel = C_NULL
socket.slot = C_NULL
end
socket.debug && @warn "c_shutdown_callback"
close(socket.ch)
close(socket.readbuf)
close(socket.writebuf)
socket.channel = C_NULL
socket.slot = C_NULL
aws_channel_destroy(channel)
return
end

Expand Down
23 changes: 22 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ data = String(read(sock, 100))
close(sock)

println("testing tls upgrade")
Sockets.set_log_level!(7)
sock = Sockets.Client("www.google.com", 443; tls=false, buffer_capacity=2^12, debug=true)
AwsIO.Sockets.tlsupgrade!(sock; ssl_alpn_list="http/1.1")
write(sock, "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n")
sleep(0.1)
data = String(read(sock, 100))
data = String(read(sock, 1000))
@test startswith(data, "HTTP/1.1 200 OK")
data = String(read(sock, 1000))
data = String(read(sock, 1000))
data = String(read(sock, 1000))
data = String(read(sock, 1000))
close(sock)

end



# using Test, AwsIO
# import AwsIO: AwsIO, Sockets
# println("testing tls upgrade")
# Sockets.set_log_level!(4)
# sock = Sockets.Client("www.google.com", 443; tls=false, buffer_capacity=2^12, debug=true)
# AwsIO.Sockets.tlsupgrade!(sock; ssl_alpn_list="http/1.1")
# write(sock, "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n")
# sleep(0.1)
# data = String(read(sock, 1000))
# data = String(read(sock, 1000))
# data = String(read(sock, 1000))
# data = String(read(sock, 1000))
# data = String(read(sock, 1000))

0 comments on commit 6a43d8a

Please # to comment.