Skip to content

Commit dbcc82a

Browse files
committed
fix(stream): free sigQ when destroy the stream
1 parent 41b3716 commit dbcc82a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

c_src/quicer_owner_queue.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ limitations under the License.
1717
#define QUICER_OWNER_QUEUE_H_
1818

1919
#include <erl_nif.h>
20+
21+
// clang-format off
2022
#include <quicer_internal.h>
2123
#include <msquic.h>
2224
#include <quic_platform.h>
23-
25+
// clang-format on
2426

2527
#define QUICER_OWNER_SIGNAL 'E0rQ' // 'Er0d' QUICER_OWNER_SIGNAL
2628

c_src/quicer_stream.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static void reset_stream_recv(QuicerStreamCTX *s_ctx);
6262
static int
6363
signal_or_buffer(QuicerStreamCTX *s_ctx, ErlNifPid *owner, ERL_NIF_TERM sig);
6464

65+
static int flush_sig_buffer(ErlNifEnv *env, QuicerStreamCTX *s_ctx);
66+
6567
QUIC_STATUS
6668
ServerStreamCallback(HQUIC Stream, void *Context, QUIC_STREAM_EVENT *Event)
6769
{
@@ -132,6 +134,7 @@ ServerStreamCallback(HQUIC Stream, void *Context, QUIC_STREAM_EVENT *Event)
132134

133135
if (is_destroy)
134136
{
137+
flush_sig_buffer(NULL, s_ctx);
135138
s_ctx->is_closed = TRUE;
136139
}
137140

@@ -232,6 +235,7 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
232235
if (is_destroy)
233236
{
234237
s_ctx->is_closed = TRUE;
238+
flush_sig_buffer(NULL, s_ctx);
235239
MsQuic->SetCallbackHandler(Stream, NULL, NULL);
236240
}
237241

@@ -1296,7 +1300,7 @@ signal_or_buffer(QuicerStreamCTX *s_ctx,
12961300

12971301
// s_ctx MUST be locked
12981302
int
1299-
flush_sig_buffer(__unused_parm__ ErlNifEnv *env, QuicerStreamCTX *s_ctx)
1303+
flush_sig_buffer(ErlNifEnv *env, QuicerStreamCTX *s_ctx)
13001304
{
13011305
OWNER_SIGNAL *sig = NULL;
13021306
if (!s_ctx->sig_queue)
@@ -1307,7 +1311,7 @@ flush_sig_buffer(__unused_parm__ ErlNifEnv *env, QuicerStreamCTX *s_ctx)
13071311
while ((sig = OwnerSignalDequeue(s_ctx->sig_queue)))
13081312
{
13091313
// if send failed, msg will be cleared in `OwnerSignalQueueDestroy`
1310-
enif_send(NULL, &(s_ctx->owner->Pid), NULL, sig->msg);
1314+
enif_send(env, &(s_ctx->owner->Pid), NULL, sig->msg);
13111315

13121316
OwnerSignalFree(sig);
13131317
}

test/prop_stream_sig_queue.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
%%%%%%%%%%%%%%%%%%
99
prop_buffer_sig_err_none() ->
1010
?FORALL(
11-
{#prop_handle{handle = S}, Pid, Term},
11+
{#prop_handle{handle = S, destructor = Destructor}, Pid, Term},
1212
{valid_stream(), pid(), term()},
1313
begin
1414
Res = quicer_nif:buffer_sig(S, Pid, Term),
15+
Destructor(),
1516
Res == {error, none}
1617
end
1718
).
@@ -97,7 +98,7 @@ receive_n(N, Ref, Acc) ->
9798
receive_n(N - 1, Ref, [X | Acc]);
9899
{quic, _, _, _} = _Drop ->
99100
receive_n(N, Ref, Acc)
100-
after 1000 ->
101+
after 500 ->
101102
{timeout, N}
102103
end.
103104

0 commit comments

Comments
 (0)