Просмотр исходного кода

feat(quic): workaround to flushing the send buffer after conn shutdown

Could not find a way to ensure msquic flush the send buffer after
calling ConnectionShutdown.

So just close the ctrl stream and let conn owner shutdown the conn.
William Yang 3 лет назад
Родитель
Сommit
5bdcb0562d
2 измененных файлов с 16 добавлено и 3 удалено
  1. 9 0
      apps/emqx/src/emqx_quic_connection.erl
  2. 7 3
      apps/emqx/src/emqx_quic_stream.erl

+ 9 - 0
apps/emqx/src/emqx_quic_connection.erl

@@ -255,6 +255,15 @@ handle_call(_Req, _From, S) ->
 
 %% @doc handle DOWN messages from streams.
 %% @TODO handle DOWN from supervisor?
+handle_info({'DOWN', _Ref, process, Pid, Reason}, #{ctrl_pid := Pid, conn := Conn} = S) ->
+    case Reason of
+        normal ->
+            quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0);
+        _ ->
+            %% @TODO have some reasons mappings here.
+            quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 1)
+    end,
+    {ok, S};
 handle_info({'DOWN', _Ref, process, Pid, Reason}, #{streams := Streams} = S) when
     Reason =:= normal orelse
         Reason =:= {shutdown, protocol_error}

+ 7 - 3
apps/emqx/src/emqx_quic_stream.erl

@@ -164,9 +164,13 @@ fast_close({ConnOwner, Conn, _ConnInfo}) when is_pid(ConnOwner) ->
     %% handshake aborted.
     quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0),
     ok;
-fast_close({quic, Conn, _Stream, _Info}) ->
-    %% Since we shutdown the control stream, we shutdown the connection as well
-    quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0),
+fast_close({quic, _Conn, Stream, _Info}) ->
+    %% Force flush
+    quicer:async_shutdown_stream(Stream),
+    %% @FIXME Since we shutdown the control stream, we shutdown the connection as well
+    %% *BUT* Msquic does not flush the send buffer if we shutdown the connection after
+    %% gracefully shutdown the stream.
+    % quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0),
     ok.
 
 -spec ensure_ok_or_exit(atom(), list(term())) -> term().