1

I'm using cpprestsdk on the client and .net core 2.1 on the server side. Everything works except the closing part.

// C++
web::websockets::client::websocket_callback_client _client;
//connecting and working with websocket...
_client.close().wait();

// C#
while (!Socket.CloseStatus.HasValue)
{
    //sending/reciving data
}
await Socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Connection closed", CancellationToken.None);

The issue is that the _client.close().wait(); never exits. The server gets the close request and calls CloseOutputAsync successfully. And I can't figure out why it never exits _client.close().wait();. It looks like there is some issue with the handshake between C++ and .net core implementations and didn't manage to make a workaround. Is there any way of forcing _client.close().wait(); to close the connection and do not wait for the handshake part from the server? Or is there is something wrong with the server code of closing a web socket?

sibvic
  • 1,622
  • 2
  • 12
  • 19
  • 1
    I'm not a C++ expert or even a beginner. But can't you just call `_client.close()` and leave it at that? – MindSwipe Feb 12 '19 at 09:47
  • @MindSwipe Unfortunately, it'll not work. _client.close() will be C# equivalent of Task t = _client.close(); (without await). This task still will wait forever. – sibvic Feb 13 '19 at 05:19

1 Answers1

0

It was my own mistake. I have set the _client.set_close_handler(...) which use lock_guard. This cases a deadlock since this mutex was locked during the close() call.

sibvic
  • 1,622
  • 2
  • 12
  • 19