CiscoDevNet / ydk-gen

Generate model-driven APIs from YANG models
http://ciscodevnet.github.io/ydk-gen/
Apache License 2.0
137 stars 74 forks source link

Segfault in CRUDService.read() #535

Closed knightjoel closed 6 years ago

knightjoel commented 7 years ago

Hi. I'm seeing a segmentation fault in CRUDService.read() if I call this method multiple times in the same script:

from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xe import CISCO_CDP_MIB
from ydk.models.cisco_ios_xe import IF_MIB

address = '172.26.47.103'
username = 'admin'
password = 'cisco123'

provider = NetconfServiceProvider(address=address,
                  username=username,
                  password=password,
                  protocol='ssh',
                  port=830)

crud = CRUDService()

cdp = CISCO_CDP_MIB.CiscoCdpMib()
cdp = crud.read(provider, cdp)

if len(cdp.cdpcachetable.cdpcacheentry) > 0:
    print("**** CDP neighbor count: {}".format(len(cdp.cdpcachetable.cdpcacheentry)))
else:
    print("**** There are no CDP neighbors")

intf = IF_MIB.IfMib()
intf = crud.read(provider, intf)
print("**** Interface count: {}".format(len(intf.iftable.ifentry)))

The above script seg faults:

~/git/sdapov% python issue.py
**** CDP neighbor count: 1
[2]    59312 segmentation fault  python issue.py

However, if I reverse the order of operations and call crud.read() against the IF_MIB first, the script runs fine:

--- issue.py    2017-08-31 11:40:06.000000000 -0600
+++ issue2.py   2017-08-31 11:41:41.000000000 -0600
@@ -16,6 +16,10 @@

 crud = CRUDService()

+intf = IF_MIB.IfMib()
+intf = crud.read(provider, intf)
+print("**** Interface count: {}".format(len(intf.iftable.ifentry)))
+
 cdp = CISCO_CDP_MIB.CiscoCdpMib()
 cdp = crud.read(provider, cdp)

@@ -24,6 +28,3 @@
 else:
     print("**** There are no CDP neighbors")

-intf = IF_MIB.IfMib()
-intf = crud.read(provider, intf)
-print("**** Interface count: {}".format(len(intf.iftable.ifentry)))
~/git/sdapov% python issue2.py
**** Interface count: 74
**** CDP neighbor count: 1

I appologize, but I don't know how or where to start debugging this.

YDK-Py 0.6.0 libydk 0.6.0 Python 2.7.10 macOS 10.11.6

Python modules: ncclient (0.5.3) pip (9.0.1) pybind11 (2.1.1) setuptools (36.3.0) six (1.10.0) wheel (0.29.0) ydk (0.6.0) ydk-models-cisco-ios-xe (16.6.1) ydk-models-cisco-ios-xr (6.2.2) ydk-models-ietf (0.1.3) ydk-models-openconfig (0.1.3)

psykokwak4 commented 7 years ago

Thanks for catching these bugs, you can enabled logging following steps in documentation here.

Please use DEBUG level:

log.setLevel(logging.DEBUG)
psykokwak4 commented 7 years ago

And also, the common causes for segfault would be:

  1. Exceptions raised in C++ side not propagated to Python side.
  2. Problems using pybind11 interface(for example, #528)

To reproduce segfault caused by the first reason, you could modify CMakeList.txt, add customized tests here. And use lldb/gdb for debugging.

knightjoel commented 7 years ago

debug log attached.

debug.txt

knightjoel commented 7 years ago

I had a go at running the unit tests but got stuck. The C++ instructions say to "cd ydk-gen/sdk/cpp/ydk" but that directory does not exist.

~/git% ll ydk-gen/sdk/cpp/
total 36
-rw-r--r--   1 jknight  staff      8  2 Sep 10:59 .gitignore
-rw-r--r--   1 jknight  staff   7314  2 Sep 10:59 CHANGES.md
-rw-r--r--   1 jknight  staff    713  2 Sep 10:59 Copyright
-rw-r--r--   1 jknight  staff  11357  2 Sep 10:59 LICENSE
-rw-r--r--   1 jknight  staff   4960  2 Sep 10:59 README.md
drwxr-xr-x  15 jknight  staff    510  2 Sep 11:11 core/
drwxr-xr-x   6 jknight  staff    204  2 Sep 10:59 install/
drwxr-xr-x  10 jknight  staff    340  2 Sep 10:59 packages/
drwxr-xr-x  21 jknight  staff    714  2 Sep 10:59 samples/
drwxr-xr-x  31 jknight  staff   1054  2 Sep 11:07 tests/
psykokwak4 commented 7 years ago

Thanks for the log, but it seems like it is not helpful for this segfault issue, not sure the reason for segfault. The last log entry comes from path/root_data_node.cpp

Sorry, that C++ instructions seems outdated. Sharing my workflow:

# first install bundle you want to debug(xe)
$ cd sdk/cpp/core
$ mkdir build
$ cd build
$ cmake .. && sudo make install # install in libydk in debugging mode
$ cd ../../tests
# edit test files and CMakeLists.txt
$ mkdir build
$ cd build && cmake .. && make
$ lldb ./ydk_bundle_test <new-test-case-name>
ghost commented 6 years ago

Unable to reproduce on ydk 0.7.0