[sr-dev] Fwd: RPC command to close all WS connections.

Andrey Deykunov deykunov at gmail.com
Mon May 18 13:01:46 CEST 2020


---------- Forwarded message ---------
От: Andrey Deykunov <deykunov at gmail.com>
Date: пн, 18 мая 2020 г. в 12:24
Subject: RPC command to close all WS connections.
To: Daniel-Constantin Mierla <miconda at gmail.com>


Hi Daniel,

We're using two nodes (active and passive) of our PBX server in production.
When an active node becomes passive, we should forcibly close all WS
connections, established by clients on this node. So, I've added
'ws.close_all' command to websocket module to let our failover service be
able closing WS connections remotely.

I've added the following code to ws_frame.c:

void ws_rpc_close_all(rpc_t *rpc, void *ctx)
{
    ws_connection_t **list = NULL, **list_head = NULL;
    ws_connection_t *wsc = NULL;
    int ret;

    list_head = wsconn_get_list();
    if(!list_head)
        return;

    list = list_head;
    wsc = *list_head;
    while(wsc) {
        LM_WARN("Closing connection\n");
        ret = close_connection(&wsc, LOCAL_CLOSE, 1000
, str_status_normal_closure);
        wsc = *(++list);
    }
    wsconn_put_list(list_head);
}

but I think this code may be unsafe and could corrupt shared
memory, because I've got some segfaults during failovers after adding this
command.

What do you think? Is it possible to close connections properly
and safety for shared memory?

Thanks,
Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20200518/fc51acc2/attachment.html>


More information about the sr-dev mailing list