<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>От: <strong class="gmail_sendername" dir="auto">Andrey Deykunov</strong> <span dir="auto"><<a href="mailto:deykunov@gmail.com">deykunov@gmail.com</a>></span><br>Date: пн, 18 мая 2020 г. в 12:24<br>Subject: RPC command to close all WS connections.<br>To: Daniel-Constantin Mierla <<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>><br></div><br><br><div dir="ltr">Hi Daniel,<div><br></div><div>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.</div><div><br></div><div>I've added the following code to ws_frame.c:</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">ws_rpc_close_all</span>(<span style="color:rgb(78,201,176)">rpc_t</span> *<span style="color:rgb(156,220,254)">rpc</span>, <span style="color:rgb(86,156,214)">void</span> *<span style="color:rgb(156,220,254)">ctx</span>)</div><div>{</div><div>    <span style="color:rgb(78,201,176)">ws_connection_t</span> **list = <span style="color:rgb(86,156,214)">NULL</span>, **list_head = <span style="color:rgb(86,156,214)">NULL</span>;</div><div>    <span style="color:rgb(78,201,176)">ws_connection_t</span> *wsc = <span style="color:rgb(86,156,214)">NULL</span>;</div><div>    <span style="color:rgb(86,156,214)">int</span> ret;</div><br><div>    list_head = <span style="color:rgb(220,220,170)">wsconn_get_list</span>();</div><div>    <span style="color:rgb(197,134,192)">if</span>(!list_head)</div><div>        <span style="color:rgb(197,134,192)">return</span>;</div><br><div>    list = list_head;</div><div>    wsc = *list_head;</div><div>    <span style="color:rgb(197,134,192)">while</span>(wsc) {</div><div>        <span style="color:rgb(220,220,170)">LM_WARN</span>(<span style="color:rgb(206,145,120)">"Closing connection</span><span style="color:rgb(215,186,125)">\n</span><span style="color:rgb(206,145,120)">"</span>);</div><div>        ret = <span style="color:rgb(220,220,170)">close_connection</span>(&wsc, LOCAL_CLOSE, <span style="color:rgb(181,206,168)">1000</span>, str_status_normal_closure);</div><div>        wsc = *(++list);</div><div>    }</div><div>    <span style="color:rgb(220,220,170)">wsconn_put_list</span>(list_head);</div><div>}</div></div></div><div><br></div><div>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.</div><div><br></div><div>What do you think? Is it possible to close connections properly and safety for shared memory?</div><div><br></div><div>Thanks,</div><div>Andrey</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>
</div></div>