Skip to content

Commit

Permalink
fix: close msquic stream handle if start stream is failed
Browse files Browse the repository at this point in the history
msquic API Doc: StreamOpen.md

So, apps that rely on that event to trigger clean up of the stream **must** handle the case where [StreamStart](StreamStart.md) is either not ever called or fails and clean up directly.
  • Loading branch information
qzhuyan committed Oct 10, 2023
1 parent 97f6167 commit 0d56b14
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions c_src/quicer_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,11 @@ async_start_stream2(ErlNifEnv *env,
//
if (QUIC_FAILED(Status = MsQuic->StreamStart(s_ctx->Stream, start_flag)))
{
// note, stream call back would close the stream
// destroy_s_ctx should not be called here
HQUIC Stream = s_ctx->Stream;
enif_mutex_lock(s_ctx->lock);
s_ctx->is_closed = TRUE;
enif_mutex_unlock(s_ctx->lock);
MsQuic->StreamClose(Stream);
return ERROR_TUPLE_3(ATOM_STREAM_START_ERROR, ATOM_STATUS(Status));
}
// NOTE: Set is_closed to FALSE (s_ctx->is_closed = FALSE;)
Expand Down

0 comments on commit 0d56b14

Please sign in to comment.