[noPoll] Deadlock
ondrej zaruba
ondrej.zaruba en meetangee.com
Mar Feb 23 18:06:51 CET 2016
Hi,
I am using the function nopoll_thread_handlers to make the library thread safe
************************************
noPollPtr WebSocket::mutexCreate(void)
{
std::mutex * mutex = new std::mutex;
std::cout<<".................create"<<std::endl;
return static_cast<noPollPtr>(mutex);
}
void WebSocket::mutexDestroy(noPollPtr _mutex)
{
std::cout<<".................destroy"<<std::endl;
std::mutex * mutex = static_cast<std::mutex *>(_mutex);
delete mutex;
}
void WebSocket::mutexLock(noPollPtr _mutex)
{
std::cout<<".................lock"<<std::endl;
std::mutex * mutex = static_cast<std::mutex *>(_mutex);
mutex->lock();
}
void WebSocket::mutexUnlock(noPollPtr _mutex)
{
std::cout<<".................unlock"<<std::endl;
std::mutex * mutex = static_cast<std::mutex *>(_mutex);
mutex->unlock();
}
nopoll_thread_handlers(&WebSocket::mutexCreate,
&WebSocket::mutexDestroy, &WebSocket::mutexLock,
&WebSocket::mutexUnlock);
***********************************
When the socket closes (timeout on TCP socket) the library dead-locks
DEBUG PRINT:
***********************************
(proc 9668): (debug)nopoll_conn.c:3008 nopoll_conn_send_text:
Attempting to send 16 bytes
(proc 9668): (debug)nopoll_conn.c:3691 Copying into the buffer 6 bytes
of header (total memory allocated: 23)
(proc 9668): (debug)nopoll_conn.c:3705 Mask used for this delivery:
-604747364 (about to send 22 bytes)
(proc 9668): (debug)nopoll_conn.c:3743 Bytes written to the wire 22
(masked? 1, mask: 1133566964, header size: 6, length: 16)
(proc 9668): (debug)nopoll_conn.c:3781 Write operation finished with
with last result=16, bytes_written=16, requested=16, remaining=0
(conn-id=2)
.................lock
.................unlock
.................lock
.................unlock
.................lock
(proc 9668): (debug)nopoll_conn.c:2518 === START: conn-id=2 (errno=11,
session: 6, conn->handshake_ok: 1, conn->pending_ssl_accept: 0) ===
(proc 9668): (critical) nopoll_conn.c:1876 unable to readn=2, error
code was: 110 (Connection timed out) (shutting down connection)
(proc 9668): (debug)nopoll_conn.c:1436 shutting down connection id=2
(session: 6, role: client)
(proc 9668): (critical) nopoll_conn.c:2695 Received connection close,
finishing connection session
(proc 9668): (debug)nopoll_conn.c:1436 shutting down connection id=2
(session: -1, role: client)
.................unlock
.................lock
.................lock
**************************************
The problem happens because the function nopoll_ctx_foreach_conn locks
the mutex and function nopoll_ctx_unregister_conn tries to lock the
mutex again.
Más información sobre la lista de distribución noPoll