From 0d56b149ed0e74aaa171faff41794abf2acac1f5 Mon Sep 17 00:00:00 2001 From: William Yang Date: Tue, 10 Oct 2023 11:36:09 +0200 Subject: [PATCH] fix: close msquic stream handle if start stream is failed 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. --- c_src/quicer_stream.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/c_src/quicer_stream.c b/c_src/quicer_stream.c index c9feaaa9..965c1d5a 100644 --- a/c_src/quicer_stream.c +++ b/c_src/quicer_stream.c @@ -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;)