[libsoup/carlosgc/http2-warnings-on-io-error] http2: fix runtime warnings when request fails due to IO error




commit af08140b549f81f8fc7c5b3d9ea4bb68af729c92
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Tue Jun 28 11:59:37 2022 +0200

    http2: fix runtime warnings when request fails due to IO error
    
    (get:18601): libsoup-WARNING **: 11:25:03.814: (../libsoup/soup-session.c:318):soup_session_dispose: 
runtime check failed: (soup_connection_manager_get_num_conns (priv->conn_manager) == 0)
    
    (get:18601): libsoup-WARNING **: 11:25:03.814: (../libsoup/soup-connection-manager.c:78):soup_host_free: 
runtime check failed: (host->conns == NULL)
    
    This happens because we increase the in use counter of the connection
    when RST_STREAM message is sent, that is decreased when the frame is
    actually sent. In case of IO error, like socket timeout, we fail to send
    the RST_STREAM frame, and the in use counter of the connection is not
    decreased. We now process all pending closed messages when a frame fails
    to be sent due to session being closed.

 libsoup/http2/soup-client-message-io-http2.c | 30 +++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/libsoup/http2/soup-client-message-io-http2.c b/libsoup/http2/soup-client-message-io-http2.c
index 9d4bd694..3c524466 100644
--- a/libsoup/http2/soup-client-message-io-http2.c
+++ b/libsoup/http2/soup-client-message-io-http2.c
@@ -949,17 +949,45 @@ on_frame_send_callback (nghttp2_session     *session,
         return 0;
 }
 
+static gboolean
+update_connection_in_use (gpointer        key,
+                          gpointer        value,
+                          SoupConnection *conn)
+{
+        soup_connection_set_in_use (conn, FALSE);
+
+        return TRUE;
+}
+
+static void
+process_pending_closed_messages (SoupClientMessageIOHTTP2 *io)
+{
+        SoupConnection *conn = g_weak_ref_get (&io->conn);
+
+        if (!conn) {
+                g_hash_table_remove_all (io->closed_messages);
+                return;
+        }
+
+        g_hash_table_foreach_remove (io->closed_messages, (GHRFunc)update_connection_in_use, conn);
+        g_object_unref (conn);
+}
+
 static int
 on_frame_not_send_callback (nghttp2_session     *session,
                             const nghttp2_frame *frame,
                             int                  lib_error_code,
                             void                *user_data)
 {
+        SoupClientMessageIOHTTP2 *io = user_data;
         SoupHTTP2MessageData *data = nghttp2_session_get_stream_user_data (session, frame->hd.stream_id);
 
-        h2_debug (user_data, data, "[SEND] [%s] Failed: %s", frame_type_to_string (frame->hd.type),
+        h2_debug (io, data, "[SEND] [%s] Failed: %s", frame_type_to_string (frame->hd.type),
                   nghttp2_strerror (lib_error_code));
 
+        if (lib_error_code == NGHTTP2_ERR_SESSION_CLOSING)
+                process_pending_closed_messages (io);
+
         return 0;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]