Changes between Initial Version and Version 1 of Ticket #1573
- Timestamp:
- Aug 23, 2012 3:18:57 AM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #1573 – Description
initial v1 1 1 Thread 1 is reading data from the SSL socket with this sequence of events: 2 2 1. ioqueue_dispatch_read_event() in ioqueue_common_abs.c locks the ioqueue key’s mutex and calls on_read_complete() 3 3 {{{ 4 4 /* Lock the key. */ 5 5 pj_mutex_lock(h->mutex); … … 9 9 (*h->cb.on_read_complete)… 10 10 } 11 11 }}} 12 12 2. on_data_read calls asock_on_data_read() in ssl_sock_ossl.c. Here it locks the socket’s write_mutex: 13 13 {{{ 14 14 pj_lock_acquire(ssock->write_mutex); 15 15 size_ = SSL_read(ssock->ossl_ssl, data_, size_); 16 16 pj_lock_release(ssock->write_mutex); 17 17 }}} 18 18 Thread 2 is writing data to the SSL socket with this sequence of events: 19 19 1. pj_ssl_sock_send() is called which acquires the lock to the socket’s write mutex: 20 20 {{{ 21 21 pj_lock_acquire(ssock->write_mutex); 22 22 }}} 23 23 2. Eventually pj_ioqueue_send() is called from ioqueue_common_abs.c which locks the ioqueue key’s mutex: 24 24 {{{ 25 25 pj_mutex_lock(key->mutex); 26 26 }}} 27 27 So in thread 1 we lock the ioqueue key mutex followed by the socket write_mutex. In thread 2 we lock the write_mutex followed by the ioqueue key mutex. 28 28 … … 32 32 Thread 1: 33 33 1. In pj_ssl_sock_send() ssl_write is called and the ssl sock’s write_mutex is locked before the call: 34 34 {{{ 35 35 pj_lock_acquire(ssock->write_mutex); 36 36 … 37 37 … 38 38 status = ssl_write(ssock, send_key, data, *size, flags); 39 39 }}} 40 40 2. Call to ssl_write eventually leads to pj_ioqueue_send() being called and the ioqueue key’s mutex is locked (and deadlocked here): 41 {{{ 41 42 pj_mutex_lock(key->mutex); 43 }}} 42 44 43 45 Thread 2: 44 46 1. A write event leads to ioqueue_dispatch_write_event being called which locks the ioqueue key’s mutex and calls the write callback: 45 47 {{{ 46 48 pj_mutex_lock(h->mutex); 47 49 … … … 50 52 write_op->written); 51 53 } 52 54 }}} 53 55 2. asock_on_data_sent is called which locks the ssl sock’s write_mutex, and here we deadlock on the acquire: 54 56 {{{ 55 57 /* Update write buffer state */ 56 58 pj_lock_acquire(ssock->write_mutex); 59 }}} 57 60 58 61 --------------------------- 59 Note that SSL sock creates activesock with whole_data setting set as PJ_TRUE, so this causes the concurrency to be disabled in activesock.c #219: 62 Note that SSL sock creates activesock with whole_data setting set as PJ_TRUE, so this causes the concurrency to be disabled in activesock.c line 219: 63 {{{ 60 64 if (asock->whole_data) { 61 65 /* Must disable concurrency otherwise there is a race condition*/ 62 66 pj_ioqueue_set_concurrency(asock->key, 0); 63 67 } 68 }}}