@@ -17,31 +17,35 @@ function write_callback(
1717 try
1818 req = unsafe_pointer_to_objref (req_p):: gRPCRequest
1919
20+ ! isnothing (req. ex) && return typemax (Csize_t)
21+
2022 n = size * count
2123 buf = unsafe_wrap (Array, convert (Ptr{UInt8}, data), (n,))
2224
2325 handled_n_bytes_total = 0
2426 try
2527 while ! isnothing (buf) && handled_n_bytes_total < n
2628 handled_n_bytes, buf = handle_write (req, buf)
27- handled_n_bytes_total += handled_n_bytes
29+ handled_n_bytes_total += handled_n_bytes
2830 handled_n_bytes == 0 && break
2931 end
30- catch ex
32+ catch ex
3133 # Eat InvalidStateException raised on put! to closed channel
3234 ! isa (ex, InvalidStateException) && rethrow (ex)
3335 end
3436
35- # If there was an exception handle it
3637 ! isnothing (req. ex) && return typemax (Csize_t)
3738
3839 # Check that we handled the correct number of bytes
3940 # If there was no exception in handle_write this should always match
4041 if handled_n_bytes_total != n
41- req. ex = gRPCServiceCallException (
42- GRPC_INTERNAL,
43- " Recieved $(n) bytes from curl but only handled $(handled_n_bytes_total) " ,
44- )
42+ if isnothing (req. ex)
43+ req. ex = gRPCServiceCallException (
44+ GRPC_INTERNAL,
45+ " Recieved $(n) bytes from curl but only handled $(handled_n_bytes_total) " ,
46+ )
47+ end
48+
4549 # If we are response streaming unblock the task waiting on response_c
4650 ! isnothing (req. response_c) && close (req. response_c)
4751 return typemax (Csize_t)
@@ -337,7 +341,6 @@ function handle_write(req::gRPCRequest, buf::Vector{UInt8})::Tuple{Int64, Union{
337341 # Not enough data yet to read the entire header
338342 return write (req. response, buf), nothing
339343 else
340-
341344 buf_header = buf[1 : header_bytes_left]
342345 n = write (req. response, buf_header)
343346
@@ -405,11 +408,11 @@ function handle_write(req::gRPCRequest, buf::Vector{UInt8})::Tuple{Int64, Union{
405408 req. response_length = 0
406409
407410 # Handle the remaining data
408- leftover_bytes = message_bytes_left - n
411+ leftover_bytes = length (buf) - n
409412
410413 buf_leftover = nothing
411414 if leftover_bytes > 0
412- buf_leftover = unsafe_wrap (Array, pointer (buf) + n, (length ( leftover_bytes) ,))
415+ buf_leftover = unsafe_wrap (Array, pointer (buf) + n, (leftover_bytes,))
413416 end
414417
415418 return n, buf_leftover
0 commit comments