[libsoup] io-http2: restart messages in case of getting a stream refused error



commit 82fc95a0f560b5d1826a06231985763f1fa6523b
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Wed May 26 16:01:51 2021 +0200

    io-http2: restart messages in case of getting a stream refused error

 libsoup/http2/soup-client-message-io-http2.c | 23 +++++++++++++++--------
 libsoup/soup-session.c                       |  2 +-
 2 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/libsoup/http2/soup-client-message-io-http2.c b/libsoup/http2/soup-client-message-io-http2.c
index 573143b7..e7a90e5d 100644
--- a/libsoup/http2/soup-client-message-io-http2.c
+++ b/libsoup/http2/soup-client-message-io-http2.c
@@ -576,6 +576,8 @@ on_stream_close_callback (nghttp2_session *session,
 {
         SoupHTTP2MessageData *data = nghttp2_session_get_stream_user_data (session, stream_id);
         h2_debug (user_data, data, "[SESSION] Closed: %s", nghttp2_http2_strerror (error_code));
+        if (error_code == NGHTTP2_REFUSED_STREAM && data && data->state < STATE_READ_DATA)
+                data->can_be_restarted = TRUE;
 
         return 0;
 }
@@ -1331,16 +1333,19 @@ soup_client_message_io_http2_run_until_read (SoupClientMessageIO  *iface,
                                              GError              **error)
 {
         SoupClientMessageIOHTTP2 *io = (SoupClientMessageIOHTTP2 *)iface;
+        SoupHTTP2MessageData *data = get_data_for_message (io, msg);
 
         if (io_run_until (io, msg, TRUE, STATE_READ_DATA, cancellable, error))
                 return TRUE;
 
-        soup_message_set_metrics_timestamp (msg, SOUP_MESSAGE_METRICS_RESPONSE_END);
+        if (get_io_data (msg) == io) {
+                if (data->can_be_restarted)
+                        data->item->state = SOUP_MESSAGE_RESTARTING;
+                else
+                        soup_message_set_metrics_timestamp (msg, SOUP_MESSAGE_METRICS_RESPONSE_END);
 
-        if (get_io_data (msg) == io)
                 soup_client_message_io_http2_finished (iface, msg);
-        else
-                g_warn_if_reached ();
+        }
 
         return FALSE;
 }
@@ -1421,12 +1426,14 @@ io_run_until_read_async (SoupMessage *msg,
                 return;
         }
 
-        soup_message_set_metrics_timestamp (msg, SOUP_MESSAGE_METRICS_RESPONSE_END);
+        if (get_io_data (msg) == io) {
+                if (data->can_be_restarted)
+                        data->item->state = SOUP_MESSAGE_RESTARTING;
+                else
+                        soup_message_set_metrics_timestamp (msg, SOUP_MESSAGE_METRICS_RESPONSE_END);
 
-        if (get_io_data (msg) == io)
                 soup_client_message_io_http2_finished ((SoupClientMessageIO *)io, msg);
-        else
-                g_warn_if_reached ();
+        }
 
         g_task_return_error (task, error);
         g_object_unref (task);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 68d7a026..f8236657 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -3022,7 +3022,7 @@ run_until_read_done (SoupMessage          *msg,
        GError *error = NULL;
 
        soup_message_io_run_until_read_finish (msg, result, &error);
-       if (error && !item->io_started) {
+       if (error && (!item->io_started || item->state == SOUP_MESSAGE_RESTARTING)) {
                /* Message was restarted, we'll try again. */
                g_error_free (error);
                return;


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