Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault in CRUDService.read() #535

Closed
knightjoel opened this issue Aug 31, 2017 · 6 comments
Closed

Segfault in CRUDService.read() #535

knightjoel opened this issue Aug 31, 2017 · 6 comments
Labels

Comments

@knightjoel
Copy link
Contributor

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
Copy link
Contributor

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

Please use DEBUG level:

log.setLevel(logging.DEBUG)

@psykokwak4
Copy link
Contributor

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, NetconfService.kill_session should accept unsigned integer instead of signed integer #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
Copy link
Contributor Author

debug log attached.

debug.txt

@knightjoel
Copy link
Contributor Author

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
Copy link
Contributor

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 ghost added the bug label Sep 8, 2017
@ghost ghost self-assigned this Sep 11, 2017
ghost pushed a commit that referenced this issue Nov 30, 2017
#640)

* Fix yang case when two containers with same name , but different namespaces, augment one container

 * Fix golang naming to be consistent with other langs
  * Updated samples and tests
 * address #535
 * Add more debug msgs and throw exceptions to avoid segfaults
 * tcp server start/stop

* Fix golang struct member issue

* Codacy

* Address review
* Fixes #612
@ghost
Copy link

ghost commented Feb 21, 2018

Unable to reproduce on ydk 0.7.0

@ghost ghost closed this as completed Feb 21, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants