Changeset 3071


Ignore:
Timestamp:
Jan 25, 2010 1:42:56 PM (14 years ago)
Author:
bennylp
Message:

Initial commit for #1033: Assertion error when shutting down PJSIP while TCP/TLS connect is in progress and a transaction is waiting

Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_transaction.h

    r2646 r3071  
    9898    pj_uint32_t                 hashed_key;     /**< Key's hashed value.    */ 
    9999    pj_str_t                    branch;         /**< The branch Id.         */ 
    100     pjsip_tpselector            tp_sel;         /**< Transport selector.    */ 
    101100 
    102101    /* 
     
    122121    unsigned                    transport_flag; /**< Miscelaneous flag.     */ 
    123122    pj_status_t                 transport_err;  /**< Internal error code.   */ 
     123    pjsip_tpselector            tp_sel;         /**< Transport selector.    */ 
     124    pjsip_tx_data              *pending_tx;     /**< Tdata which caused 
     125                                                     pending transport flag 
     126                                                     to be set on tsx.      */ 
    124127 
    125128    /* 
  • pjproject/trunk/pjsip/include/pjsip/sip_transport.h

    r2985 r3071  
    570570    pjsip_tpselector        tp_sel; 
    571571 
     572    /** 
     573     * Arbitrary data attached by PJSIP modules. 
     574     */ 
     575    void                    *mod_data[PJSIP_MAX_MODULE]; 
    572576}; 
    573577 
  • pjproject/trunk/pjsip/src/pjsip/sip_transaction.c

    r2936 r3071  
    582582static void mod_tsx_layer_unregister_tsx( pjsip_transaction *tsx) 
    583583{ 
     584    if (mod_tsx_layer.mod.id == -1) { 
     585        /* The transaction layer has been unregistered. This could happen 
     586         * if the transaction was pending on transport and the application 
     587         * is shutdown. See http://trac.pjsip.org/repos/ticket/1033. In 
     588         * this case just do nothing. 
     589         */ 
     590        return; 
     591    } 
     592 
    584593    pj_assert(tsx->transaction_key.slen != 0); 
    585594    //pj_assert(tsx->state != PJSIP_TSX_STATE_NULL); 
     
    11161125        pj_time_val timeout = {0, 0}; 
    11171126 
    1118         /* Reschedule timeout timer to destroy this transaction. */ 
     1127        /* If we're still waiting for a message to be sent.. */ 
    11191128        if (tsx->transport_flag & TSX_HAS_PENDING_TRANSPORT) { 
    1120             tsx->transport_flag |= TSX_HAS_PENDING_DESTROY; 
    1121         } else { 
    1122             /* Cancel timeout timer. */ 
    1123             if (tsx->timeout_timer.id != 0) { 
    1124                 pjsip_endpt_cancel_timer(tsx->endpt, &tsx->timeout_timer); 
    1125                 tsx->timeout_timer.id = 0; 
    1126             } 
    1127  
    1128             tsx->timeout_timer.id = TIMER_ACTIVE; 
    1129             pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer,  
    1130                                         &timeout); 
    1131         } 
     1129            /* Disassociate ourselves from the outstanding transmit data 
     1130             * so that when the send callback is called we will be able 
     1131             * to ignore that (otherwise we'll get assertion, see 
     1132             * http://trac.pjsip.org/repos/ticket/1033) 
     1133             */ 
     1134            tsx->pending_tx->mod_data[mod_tsx_layer.mod.id] = NULL; 
     1135            tsx->pending_tx = NULL; 
     1136            tsx->transport_flag &= ~(TSX_HAS_PENDING_TRANSPORT); 
     1137        } 
     1138 
     1139        /* Cancel timeout timer. */ 
     1140        if (tsx->timeout_timer.id != 0) { 
     1141            pjsip_endpt_cancel_timer(tsx->endpt, &tsx->timeout_timer); 
     1142            tsx->timeout_timer.id = 0; 
     1143        } 
     1144 
     1145        tsx->timeout_timer.id = TIMER_ACTIVE; 
     1146        pjsip_endpt_schedule_timer( tsx->endpt, &tsx->timeout_timer, 
     1147                                    &timeout); 
    11321148 
    11331149 
     
    16371653    pjsip_tx_data *tdata = send_state->tdata; 
    16381654    struct tsx_lock_data lck; 
     1655 
     1656    /* Check if transaction has cancelled itself from this transmit 
     1657     * notification (https://trac.pjsip.org/repos/ticket/1033). 
     1658     */ 
     1659    if (tdata->mod_data[mod_tsx_layer.mod.id] == NULL) { 
     1660        return; 
     1661    } 
     1662 
     1663    /* Reset */ 
     1664    tdata->mod_data[mod_tsx_layer.mod.id] = NULL; 
     1665    tsx->pending_tx = NULL; 
    16391666 
    16401667    lock_tsx(tsx, &lck); 
     
    19071934    pjsip_tx_data_add_ref(tdata); 
    19081935 
     1936    /* Also attach ourselves to the transmit data so that we'll be able 
     1937     * to unregister ourselves from the send notification of this 
     1938     * transmit data. 
     1939     */ 
     1940    tdata->mod_data[mod_tsx_layer.mod.id] = tsx; 
     1941    tsx->pending_tx = tdata; 
     1942 
    19091943    /* Begin resolving destination etc to send the message. */ 
    19101944    if (tdata->msg->type == PJSIP_REQUEST_MSG) { 
     
    19151949        if (status == PJ_EPENDING) 
    19161950            status = PJ_SUCCESS; 
    1917         if (status != PJ_SUCCESS) 
     1951        if (status != PJ_SUCCESS) { 
    19181952            pjsip_tx_data_dec_ref(tdata); 
     1953            tdata->mod_data[mod_tsx_layer.mod.id] = NULL; 
     1954            tsx->pending_tx = NULL; 
     1955        } 
    19191956         
    19201957        /* Check if transaction is terminated. */ 
     
    19301967        if (status == PJ_EPENDING) 
    19311968            status = PJ_SUCCESS; 
    1932         if (status != PJ_SUCCESS) 
     1969        if (status != PJ_SUCCESS) { 
    19331970            pjsip_tx_data_dec_ref(tdata); 
     1971            tdata->mod_data[mod_tsx_layer.mod.id] = NULL; 
     1972            tsx->pending_tx = NULL; 
     1973        } 
    19341974 
    19351975        /* Check if transaction is terminated. */ 
Note: See TracChangeset for help on using the changeset viewer.