Skip to content

Commit

Permalink
fix bug where processing both 1. an ack to an end packet and 2. an en…
Browse files Browse the repository at this point in the history
…d packet for a stream would cause the stream to close before sending the ack to the remote. the solution is to delay setting REMOTE_ENDED until the ack is sent (#223)
  • Loading branch information
jthomas43 authored Nov 8, 2024
1 parent aa3a243 commit c0aedb5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/udx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,14 +1458,6 @@ process_packet (udx_socket_t *socket, char *buf, ssize_t buf_len, struct sockadd
}
}

if ((stream->status & UDX_STREAM_SHOULD_END_REMOTE) == UDX_STREAM_END_REMOTE && seq_compare(stream->remote_ended, stream->ack) <= 0) {
stream->status |= UDX_STREAM_ENDED_REMOTE;
if (stream->on_read != NULL) {
uv_buf_t b = uv_buf_init(NULL, 0);
stream->on_read(stream, UV_EOF, &b);
}
}

return 1;
}

Expand Down Expand Up @@ -1630,6 +1622,16 @@ send_stream_packets (udx_socket_t *socket, udx_stream_t *stream) {
if (rc == UV_EAGAIN) {
return false;
}

// if this ACK packet acks the remote's END packet, advance from ENDING_REMOTE -> ENDED_REMOTE
if ((stream->status & UDX_STREAM_SHOULD_END_REMOTE) == UDX_STREAM_END_REMOTE && seq_compare(stream->remote_ended, stream->ack) <= 0) {
stream->status |= UDX_STREAM_ENDED_REMOTE;
if (stream->on_read != NULL) {
uv_buf_t b = uv_buf_init(NULL, 0);
stream->on_read(stream, UV_EOF, &b);
}
}

stream->packets_tx++;
stream->bytes_tx += pkt->size;

Expand Down

0 comments on commit c0aedb5

Please sign in to comment.