Project

General

Profile

Bug #52

Repeated gdp_gcl_open calls on non-existing GCLs do not give proper error code (was: GDP_GCL() function in Python does not raise an error when opening a non-existing GCL)

Added by Rico Maestro almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
libgdp
Start date:
09/18/2016
Due date:
% Done:

0%


Description

When opening a non-existing GCL, the gdp.GDP_GCL function in the Python API only raises an error during the first attempt. However, if you try to open it again, it will not raise an error.

Sample code:
gdp.gdp_init()
gcl_name = gdp.GDP_NAME("this.GCL.does.not.exist")
gcl_handle = gdp.GDP_GCL(gcl_name, gdp.GDP_MODE_RO) #this will raise an error
gcl_handle = gdp.GDP_GCL(gcl_name, gdp.GDP_MODE_RO) #this will NOT raise an error

This was still working with my Feb 2016 copy of the codes.

multi-open.c Magnifier (1.02 KB) Nitesh Mor, 09/18/2016 09:17 PM

multi-open.c Magnifier - version 2 with -D flag (1.18 KB) Eric Allman, 09/23/2016 12:11 AM

History

#1 Updated by Rico Maestro almost 4 years ago

  • Project changed from Click GDP Routers to GDP
  • Category set to Python API

#2 Updated by Nitesh Mor almost 4 years ago

  • File multi-open.cMagnifier added
  • Category changed from Python API to libgdp
  • Assignee changed from Nitesh Mor to Eric Allman

Good point. There was a minor change in GDP_GCL(...) to better match it with the underlying C-API behavior. More specifically, the underlying C-API re-uses the data-structures if you open the same GCL multiple times (potentially from different threads, but not necessarily). Before commit commit:68ee5384, the Python API neglected such re-use, which meant that a single underlying C data-structure gdp_gcl_t could be mapped to multiple python GDP_GCL objects, causing numerous issues.

It turns out that this is a bug in the underlying C library, which failed to show up so far. Here's what happens in C:

    // Opening GCL for the first time                                           
    estat = gdp_gcl_open(gclname, GDP_MODE_RO, NULL, &gcl);                     
    if (!EP_STAT_ISOK(estat))                                                   
        printf("Expected behavior, EP_STAT is erroneous\n");                    

    // Opening the same GCL again                                               
    estat = gdp_gcl_open(gclname, GDP_MODE_RO, NULL, &gcl);                     
    if (!EP_STAT_ISOK(estat))                                                   
    {                                                                           
        printf("Expected behavior, EP_STAT is erroneous\n");                    
    }                                                                           
    else                                                                        
    {                                                                           
        char buf[100];                                                          
        ep_stat_tostr(estat, buf, 100);                                         
        printf("Unexpected behavior. EP_STAT: %s\n", buf);                      
    }                                                                           

The output is:

Expected behavior, EP_STAT is erroneous
Unexpected behavior. EP_STAT: OK

See attached for a full sample code. Assigning this to Eric.

#3 Updated by Eric Allman almost 4 years ago

  • File multi-open.cMagnifier added
  • Subject changed from GDP_GCL() function in Python does not raise an error when opening a non-existing GCL to Repeated gdp_gcl_open calls on non-existing GCLs do not give proper error code (was: GDP_GCL() function in Python does not raise an error when opening a non-existing GCL)
  • Status changed from New to Feedback

Problem was that the unopened GCL was being kept in the cache; the subsequent calls to gdp_gcl_open found the cached version and assumed it was correct. There were two possible solutions: mark the cached version as failed, or remove the cache entry entirely. I opted for the latter, since someone could come along later and fix the problem. Fixed in commit:079043b8.

There's also an improved version of the test program attached that lets you set debugging without recompiling.

#4 Updated by Nitesh Mor almost 4 years ago

  • Status changed from Feedback to Closed

Seems to work. Closing the issue.

Also available in: Atom PDF