libsoup websocket server memory problems

Hello libsoup mailing list members,

I'm using the libsoup websocket server and recently updated my libsoup from 2.64.2 to 2.68.3 due to a bug that has been fixed with

Since then I have a new problem, which I better explain using this simple example code:

static void websocket_client_message_cb(SoupWebsocketConnection *ws, SoupWebsocketDataType type, GBytes *message, gpointer user_data) {
    (void) ws; (void) type; (void) message; (void) user_data;
    g_message("%s", __func__);

static void websocket_client_closed_cb(SoupWebsocketConnection *ws, gpointer user_data) {
    (void) user_data;
    g_message("%s", __func__);

static void websocket_client_error_cb(SoupWebsocketConnection *ws, GError *error, gpointer user_data)'{
    (void) ws; (void) error; (void) user_data;
    g_message("%s", __func__);

static void websocket_client_connect_cb(SoupServer *server, SoupWebsocketConnection *ws,
        const char *path, SoupClientContext *client, gpointer user_data) {
    (void) server; (void) client; (void) user_data; (void) path;
    g_signal_connect(ws, "message", G_CALLBACK(websocket_client_message_cb), NULL);
    g_signal_connect(ws, "closed",  G_CALLBACK(websocket_client_closed_cb), NULL);
    g_signal_connect(ws, "error",   G_CALLBACK(websocket_client_error_cb), NULL);
    g_message("%s", __func__);

int main(int argc, char* argv[]) {
    GMainLoop *mainloop = g_main_loop_new(0, FALSE);

    /* play here */
    GError *error = NULL;
    SoupServer *server = soup_server_new(NULL, NULL);
    soup_server_listen_all(server, 33333, 0, &error);
    soup_server_add_websocket_handler(server, "/", NULL, NULL, websocket_client_connect_cb,          NULL, NULL);
    g_message("ws server started");

    /* run mainloop */

This starts a simple websocket server with 1 handler and registers the usual signal callbacks. The new problem is, every time a websocket client disconnects from this server, I run into this g_assert:

[benjamin@pc-0480-19-0139 spielwiese]$ ./main
** Message: 11:08:27.392: ws server started
** Message: 11:08:33.295: websocket_client_connect_cb
** Message: 11:08:34.709: websocket_client_closed_cb
libsoup:ERROR:../libsoup/soup-websocket-connection.c:1445:soup_websocket_connection_finalize: assertion failed: (!pv->input_source)
Bail out! libsoup:ERROR:../libsoup/soup-websocket-connection.c:1445:soup_websocket_connection_finalize: assertion failed: (!pv->input_source)
Aborted (core dumped)
[benjamin@pc-0480-19-0139 spielwiese]$

This assertion is new and did not happen before the commit I mentioned at the beginning. I do NOT run into this g_assert if I'm either not using g_object_unref(ws) in function websocket_client_closed_cb or delay it by 1s. But I HAVE to use g_object_ref(ws) in function websocket_client_connect_cb otherwise the SoupWebsocketConnection *ws would not survive. After I discovered that, I took a look into your regression code (namely tests/websocket-tests.c) and found you doing the same: g_object_ref(ws) on every client connect and no g_object_unref(ws) on "closed".

At last, I used valgrind on my example code and found out that it's pretty leaky w/o g_object_unref(ws).

So my question: did I do something wrong in my example code or is this possibly a bug?

With best regards

Benjamin Reikowski

Wir ziehen um! Bitte beachten Sie unsere neue Anschrift ab 1.4.2020:
We're moving! Please note our new address from 1.4.2020:

DResearch Fahrzeugelektronik GmbH
Tor 2, Aufgang R (R03.020)
Wolfener Straße 36
12681 Berlin

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