Changes between Initial Version and Version 1 of Ticket #1573


Ignore:
Timestamp:
Aug 23, 2012 3:18:57 AM (12 years ago)
Author:
ming
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #1573 – Description

    initial v1  
    11Thread 1 is reading data from the SSL socket with this sequence of events: 
    221. ioqueue_dispatch_read_event() in ioqueue_common_abs.c locks the ioqueue key’s mutex and calls on_read_complete() 
    3  
     3{{{ 
    44/* Lock the key. */ 
    55pj_mutex_lock(h->mutex); 
     
    99    (*h->cb.on_read_complete)… 
    1010} 
    11  
     11}}} 
    12122. on_data_read calls asock_on_data_read() in ssl_sock_ossl.c. Here it locks the socket’s write_mutex: 
    13  
     13{{{ 
    1414pj_lock_acquire(ssock->write_mutex); 
    1515size_ = SSL_read(ssock->ossl_ssl, data_, size_); 
    1616pj_lock_release(ssock->write_mutex); 
    17   
     17}}} 
    1818Thread 2 is writing data to the SSL socket with this sequence of events: 
    19191. pj_ssl_sock_send() is called which acquires the lock to the socket’s write mutex: 
    20  
     20{{{ 
    2121pj_lock_acquire(ssock->write_mutex); 
    22  
     22}}} 
    23232. Eventually pj_ioqueue_send() is called from ioqueue_common_abs.c which locks the ioqueue key’s mutex: 
    24  
     24{{{ 
    2525pj_mutex_lock(key->mutex); 
    26  
     26}}} 
    2727So 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. 
    2828 
     
    3232Thread 1: 
    33331. In pj_ssl_sock_send() ssl_write is called and the ssl sock’s write_mutex is locked before the call: 
    34  
     34{{{ 
    3535pj_lock_acquire(ssock->write_mutex); 
    3636 
    3737 
    3838status = ssl_write(ssock, send_key, data, *size, flags); 
    39  
     39}}} 
    40402. Call to ssl_write eventually leads to pj_ioqueue_send() being called and the ioqueue key’s mutex is locked (and deadlocked here): 
     41{{{ 
    4142pj_mutex_lock(key->mutex); 
     43}}} 
    4244 
    4345Thread 2: 
    44461. 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{{{ 
    4648pj_mutex_lock(h->mutex); 
    4749 
     
    5052    write_op->written); 
    5153} 
    52  
     54}}} 
    53552. asock_on_data_sent is called which locks the ssl sock’s write_mutex, and here we deadlock on the acquire: 
    54  
     56{{{ 
    5557/* Update write buffer state */ 
    5658pj_lock_acquire(ssock->write_mutex); 
     59}}} 
    5760 
    5861--------------------------- 
    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: 
     62Note 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{{{ 
    6064    if (asock->whole_data) { 
    6165        /* Must disable concurrency otherwise there is a race condition*/ 
    6266        pj_ioqueue_set_concurrency(asock->key, 0); 
    63  
     67    } 
     68}}}