mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-28 14:40:45 +02:00
nmcs-http: fix multiple HTTP request bug
Since just a single pointer is used to store the socket's GSource if more than 1 consecutive request was done through the same HTTP provider the 2nd request would clear the GSource associated to the second request causing the 1st HTTP request to never complete and end up in a expired timeout. Use a hashtable instead so we can correctly track all requests. https://bugzilla.redhat.com/show_bug.cgi?id=1821787 Fixes:69f048bf0c('cloud-setup: add tool for automatic IP configuration in cloud') (cherry picked from commit427fbc85f0) (cherry picked from commitf5487645d8) (cherry picked from commitfe3ddf3eff)
This commit is contained in:
parent
ae35fa83e3
commit
e9f865b365
1 changed files with 16 additions and 6 deletions
|
|
@ -17,7 +17,7 @@ typedef struct {
|
|||
GMainContext *context;
|
||||
CURLM *mhandle;
|
||||
GSource *mhandle_source_timeout;
|
||||
GSource *mhandle_source_socket;
|
||||
GHashTable *source_sockets_hashtable;
|
||||
} NMHttpClientPrivate;
|
||||
|
||||
struct _NMHttpClient {
|
||||
|
|
@ -616,12 +616,13 @@ _mhandle_socket_cb (int fd,
|
|||
static int
|
||||
_mhandle_socketfunction_cb (CURL *e_handle, curl_socket_t fd, int what, void *user_data, void *socketp)
|
||||
{
|
||||
GSource *source_socket;
|
||||
NMHttpClient *self = user_data;
|
||||
NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE (self);
|
||||
|
||||
(void) _NM_ENSURE_TYPE (int, fd);
|
||||
|
||||
nm_clear_g_source_inst (&priv->mhandle_source_socket);
|
||||
g_hash_table_remove (priv->source_sockets_hashtable, GINT_TO_POINTER (fd));
|
||||
|
||||
if (what != CURL_POLL_REMOVE) {
|
||||
GIOCondition condition = 0;
|
||||
|
|
@ -636,9 +637,13 @@ _mhandle_socketfunction_cb (CURL *e_handle, curl_socket_t fd, int what, void *us
|
|||
condition = 0;
|
||||
|
||||
if (condition) {
|
||||
priv->mhandle_source_socket = g_unix_fd_source_new (fd, condition);
|
||||
g_source_set_callback (priv->mhandle_source_socket, G_SOURCE_FUNC (_mhandle_socket_cb), self, NULL);
|
||||
g_source_attach (priv->mhandle_source_socket, priv->context);
|
||||
source_socket = g_unix_fd_source_new (fd, condition);
|
||||
g_source_set_callback (source_socket, G_SOURCE_FUNC (_mhandle_socket_cb), self, NULL);
|
||||
g_source_attach (source_socket, priv->context);
|
||||
|
||||
g_hash_table_insert (priv->source_sockets_hashtable,
|
||||
GINT_TO_POINTER (fd),
|
||||
source_socket);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -675,6 +680,11 @@ _mhandle_timerfunction_cb (CURLM *multi, long timeout_msec, void *user_data)
|
|||
static void
|
||||
nm_http_client_init (NMHttpClient *self)
|
||||
{
|
||||
NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE (self);
|
||||
priv->source_sockets_hashtable = g_hash_table_new_full (nm_direct_hash,
|
||||
NULL,
|
||||
NULL,
|
||||
(GDestroyNotify) nm_g_source_destroy_and_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -711,9 +721,9 @@ dispose (GObject *object)
|
|||
NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE (self);
|
||||
|
||||
nm_clear_pointer (&priv->mhandle, curl_multi_cleanup);
|
||||
nm_clear_pointer (&priv->source_sockets_hashtable, g_hash_table_unref);
|
||||
|
||||
nm_clear_g_source_inst (&priv->mhandle_source_timeout);
|
||||
nm_clear_g_source_inst (&priv->mhandle_source_socket);
|
||||
|
||||
G_OBJECT_CLASS (nm_http_client_parent_class)->dispose (object);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue