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