CESNET / netopeer2

NETCONF toolset
BSD 3-Clause "New" or "Revised" License
296 stars 187 forks source link

Notifications failing while acquiring context #1451

Open jbn98 opened 12 months ago

jbn98 commented 12 months ago

Hi Team

I am using below packages

libnetconf2-2.1.28 libyang-2.1.30 netopeer2-2.1.49 sysrepo-2.2.36

While sending the notification to the client I have observed some errors from the sysrepo. It says the 'failed to acquire context'. I will attach the error messages and the code snippet. Can you kindly look into this and tell me what I might be doing wrong and causing the issue. Thank you for you help in advance

------------CODE SNIPPET--------------

void                                                                            
notifyClient (void)                                                             
{                                                                               

    struct lyd_node *notif = NULL;                                              
#if (SYSREPO_VERSION == SYSREPO_v1_x_x)                                         

    /* Create the notification */                                               
    notif = lyd_new_path (                                                      
        NULL,                                                                   
        sr_get_context (sr_session_get_connection (global_pri_data->session)),  
        SUPERVISION_NOTIF_XPATH, NULL, 0, 0);                                   
#elif (SYSREPO_VERSION == SYSREPO_v2_x_x)                                       

    /* Create the notification */                                               
    const struct ly_ctx *ctx = sr_session_acquire_context(global_pri_data->session);
    if (ctx == NULL)                                                            
        {                                                                       
            PRINT(ERR, program_invocation_short_name,                           
                    "Failed to acquire context%s", "\n");                       
            return;                                                             
        }                                                                       
    lyd_new_path (                                                              
        NULL,                                                                   
        ctx,                                                                    
        SUPERVISION_NOTIF_XPATH, NULL, 0, &notif);                              
#endif                                                                          
    if (notif == NULL)                                                          
        {                                                                       
            PRINT (ERR, program_invocation_short_name, "lyd_new_path failed%s", 
                   "\n");                                                       
            return;                                                             
        }                                                                       

    /* Send the notification */                                                 
    if (SR_NOTIF_SEND_TREE (global_pri_data->session, notif, 0, 0) != SR_ERR_OK)
        {                                                                       
            PRINT (ERR, program_invocation_short_name,                          
                "Failed to send the notification%s", "\n");                     
        }                                                                       
    if (notif != NULL)                                                          
        {                                                                       
            LYD_FREE_API (notif);                                               
            sr_session_release_context(global_pri_data->session);               
        }                                                                       

    return;                                                                     
}      

------------------ERROR LOGS--------------------

[ERR] Internal error (/usr/src/debug/sysrepo-2-x-x/v2.2.36-r0/git/src/common.c:4185).
[ERR] Locking a mutex failed (sr_acquire_context: Connection timed out).
[ERR] Internal error (/usr/src/debug/sysrepo-2-x-x/v2.2.36-r0/git/src/common.c:4264).
ERR (supervision): Failed to acquire context
ERR (supervision): lyd_new_path failed
[ERR] Locking a mutex failed (sr_release_context: Connection timed out).
michalvasko commented 11 months ago

It would be best if you tried it using the current sysrepo in the devel branch, there were quite a lot of changes already made. But it is a rather weird mutex that you seem not be able to lock and I am not sure what the problem may be.

jbn98 commented 11 months ago

Hi @michalvasko Thank you for your reply. I am calling the function notifyClient from a thread (attaching the code snippet ). Will that cause any issue?. Just want to check whether the issue is from my side.

          /*----------CRITICAL SECTION-------------*/                        

        pthread_mutex_lock (&lock1);                                        
        PRINT (LOG, program_invocation_short_name,                          
               "Notifying client:%d \n", current->det.nc_sid);              

        /** Send notification to the client */                              
        notifyClient ();                                                    

        pthread_mutex_unlock (&lock1);                                      
         /*--------------------------------------*/  
michalvasko commented 11 months ago

Like I said, if you want my assistance you will have to start by updating the used sysrepo and the other projects to their latest devel versions. It is quite possible this is some locking issue and that is one aspect that has been significantly improved since the version you are using.