diff --git a/c_src/quicer_connection.c b/c_src/quicer_connection.c index cb4276ed..18dd0de7 100644 --- a/c_src/quicer_connection.c +++ b/c_src/quicer_connection.c @@ -1413,9 +1413,7 @@ handle_connection_event_peer_stream_started(QuicerConnCTX *c_ctx, { if (is_orphan) { - // Connection owner is dead - // we should not destroy the acceptor, because it is owned by the - return selected_owner_unreachable(s_ctx); // cheat + return selected_owner_unreachable(s_ctx); } else { @@ -1426,6 +1424,7 @@ handle_connection_event_peer_stream_started(QuicerConnCTX *c_ctx, AcceptorDestroy(acc); // Set is_orphan to true, connection owner takeover props_value[1] = ATOM_TRUE; + acc = AcceptorAlloc(); CxPlatCopyMemory(acc, c_ctx->owner, sizeof(ACCEPTOR)); s_ctx->owner = acc; @@ -1852,9 +1851,7 @@ selected_owner_unreachable(QuicerStreamCTX *s_ctx) { // // s_ctx ownership transfer failed - // We must release ctx twice, here and in `destroy_s_ctx`. - // AND - // no callback from msquic + // There is no shared ownership, we must destroy the s_ctx here // s_ctx->is_closed = TRUE; enif_clear_env(s_ctx->env); diff --git a/c_src/quicer_stream.c b/c_src/quicer_stream.c index ae7d8746..9b675c8f 100644 --- a/c_src/quicer_stream.c +++ b/c_src/quicer_stream.c @@ -958,15 +958,13 @@ handle_stream_event_recv(HQUIC Stream, { // Owner is waiting for data // notify owner to trigger async recv // - if (!enif_send( - NULL, - &(s_ctx->owner->Pid), - NULL, - make_event(env, - ATOM_QUIC_STATUS_CONTINUE, - // @TODO eHandle is in env, no need to copy? - enif_make_copy(env, s_ctx->eHandle), - ATOM_UNDEFINED))) + if (!enif_send(NULL, + &(s_ctx->owner->Pid), + NULL, + make_event(env, + ATOM_QUIC_STATUS_CONTINUE, + enif_make_copy(env, s_ctx->eHandle), + ATOM_UNDEFINED))) { // App down, shutdown stream MsQuic->StreamShutdown(Stream, diff --git a/c_src/quicer_tp.c b/c_src/quicer_tp.c index 0824031d..2323525e 100644 --- a/c_src/quicer_tp.c +++ b/c_src/quicer_tp.c @@ -47,6 +47,8 @@ tp_snk(ErlNifEnv *env, { ErlNifPid *pid = &GLOBAL_SNAB_KC_PID; + // avoid polluting the context env, + // use tmp env for message passing, env = enif_alloc_env(); ERL_NIF_TERM snk_event;