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

Occasional stucks with snimpy 1.0.2, working with 1.0.0 #111

Open
markkuleinio opened this issue Apr 4, 2024 · 14 comments
Open

Occasional stucks with snimpy 1.0.2, working with 1.0.0 #111

markkuleinio opened this issue Apr 4, 2024 · 14 comments

Comments

@markkuleinio
Copy link

Occasionally snimpy 1.0.2 is just stuck, nothing is returned, and tcpdump shows that only the first bulk request was sent (and received response correctly). Example:

$ python
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snimpy.manager import Manager as SNMPManager
>>> from snimpy.manager import load
>>> m = SNMPManager("10.10.10.10", "my_community", 2, cache=3, timeout=1, retries=1)
>>> load("SNMPv2-MIB")
>>> load("IF-MIB")
>>> for index, value in m.ifName.iteritems():
...     print(index, value)
...
(****** waited here, eventually pressed Ctrl-C ******)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/snimpy/manager.py", line 454, in iteritems
    for noid, result in self.session.walk(oid):
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/snimpy/manager.py", line 127, in walk
    return self.getorwalk("walkmore", *args)
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/snimpy/manager.py", line 112, in getorwalk
    value = getattr(self._session, op)(*args)
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/snimpy/snmp.py", line 312, in walkmore
    return self._op(self._cmdgen.bulkCmd, *args)
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/snimpy/snmp.py", line 264, in _op
    errorIndication, errorStatus, errorIndex, varBinds = cmd(
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 100, in bulkCmd
    for errorIndication, errorStatus, errorIndex, varBinds in sync.bulkWalkCmd(
  File "/home/markku/temp/snimpy/venv/lib/python3.9/site-packages/pysnmp/hlapi/asyncio/sync/cmdgen.py", line 679, in bulkWalkCmd
    result = loop.run_until_complete(run())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1854, in _run_once
    event_list = self._selector.select(timeout)
  File "/usr/lib/python3.9/selectors.py", line 469, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
KeyboardInterrupt
>>> Ctrl-D to exit the REPL
Task was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<AsyncioDispatcher.handle_timeout()
running at /home/markku/temp/snimpy/venv/lib/python3.9/site-packages/pysnmp/carrier/asyncio/dispatch.py:62>
wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f6fe306ef70>()]>>
$

(line breaks added in the task error for clarity)

If it doesn't fail the first time, just repeat the for statement and see that it fails within a few retries.

I'm unable to reproduce the problem in snimpy 1.0.0.

@vincentbernat
Copy link
Owner

vincentbernat commented Apr 4, 2024 via email

@markkuleinio
Copy link
Author

I'm using whatever is currently (as of today) installed when installed either snimpy==1.0.0 or snimpy==1.0.2 in a new venv:

With 1.0.0:

$ pip freeze
cffi==1.16.0
pkg_resources==0.0.0
ply==3.11
pyasn1==0.6.0
pycparser==2.22
pycryptodomex==3.20.0
pysmi==0.3.4
pysnmp==4.4.12
snimpy==1.0.0

With 1.0.2:

$ pip freeze
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.5
idna==3.6
Jinja2==3.1.3
MarkupSafe==2.1.5
pkg_resources==0.0.0
ply==3.11
pyasn1==0.6.0
pycparser==2.22
pysmi-lextudio==1.4.3
pysnmp-lextudio==6.1.2
pysnmpcrypto==0.0.4
requests==2.31.0
snimpy==1.0.2
urllib3==2.2.1

@markkuleinio
Copy link
Author

markkuleinio commented Apr 4, 2024

Also stucks with snimpy 1.0.1

$ pip freeze
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.5
idna==3.6
Jinja2==3.1.3
MarkupSafe==2.1.5
pkg_resources==0.0.0
ply==3.11
pyasn1==0.6.0
pycparser==2.22
pysmi-lextudio==1.4.3
pysnmp-lextudio==6.1.2
pysnmpcrypto==0.0.4
requests==2.31.0
snimpy==1.0.1
urllib3==2.2.1

1.0.0...1.0.1

@markkuleinio
Copy link
Author

I installed snimpy 1.0.2, then uninstalled some packages and installed pysnmp, like this:

$ pip freeze
cffi==1.16.0
pkg_resources==0.0.0
ply==3.11
pyasn1==0.6.0
pycparser==2.22
pycryptodomex==3.20.0
pysmi==0.3.4
pysnmp==4.4.12
pysnmpcrypto==0.0.4
snimpy==1.0.2

and I'm not able to get any stuck requests anymore.

@vincentbernat
Copy link
Owner

Unfortunately, there are many changes in pysnmp-lextudio. I had to upgrade to support more recent versions of Python. It now requires a more important rewrite starting from PySNMP 6. It could fix this issue, but it does not seem trivial.

@markkuleinio
Copy link
Author

Ok, I now understand the status of pysnmp vs. pysnmp-lextudio (https://www.pysnmp.com/history).

It now requires a more important rewrite starting from PySNMP 6. It could fix this issue, but it does not seem trivial.

Sorry, I don't quite understand. Do you mean that using pysnmp-lextudio 6.x requires some further changes in snimpy in order to snimpy >1.0.0 be usable again? Or do you mean something else?

Meanwhile, using snimpy==1.0.0 (and thus pysnmp 4.4.12 that's from 2019) is apparently the way to get a working snimpy, right?

@vincentbernat
Copy link
Owner

pysnmp-lextudio < 6 was supposed to be a dropin replacement, except with compatibility with more recent versions of Python. From your bug report, it seems to not be the case. I don't think it is worth investigating the problem too much, because using pysnmp-lextudio >= 6 requires a larger adaptation of the code handling SNMP in Snimpy (the API Snimpy was using is gone).

@eduble
Copy link

eduble commented Apr 29, 2024

I can confirm the same is happening here.

@vincentbernat
Copy link
Owner

It would help to have a small reproducer as it does not happen during tests.

@markkuleinio
Copy link
Author

markkuleinio commented May 5, 2024

Sure, this is reproduceable very easily. Tested in two different:

  • sites/servers
  • SNMP agents
  • Debian 11 and Debian 12
  • Python 3.9.x and Python 3.11.x (as packaged by Debian)

This is on Debian 12:

$ cd temp
$ python3 -m venv snimpy-venv
$ . snimpy-venv/bin/activate
(snimpy-venv) $ pip install -U pip wheel
(snimpy-venv) $ pip install snimpy
(failed, libsmi is missing)
(snimpy-venv) $ sudo apt install libsmi2-dev
(snimpy-venv) $ pip install snimpy
...
Successfully installed Jinja2-3.1.3 MarkupSafe-2.1.5 certifi-2024.2.2 cffi-1.16.0 charset-normalizer-3.3.2
cryptography-42.0.6 idna-3.7 ply-3.11 pyasn1-0.6.0 pycparser-2.22 pysmi-lextudio-1.4.3
pysnmp-lextudio-6.1.2 pysnmpcrypto-0.0.4 requests-2.31.0 snimpy-1.0.2 urllib3-2.2.1
(snimpy-venv) $ pip freeze
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.6
idna==3.7
Jinja2==3.1.3
MarkupSafe==2.1.5
ply==3.11
pyasn1==0.6.0
pycparser==2.22
pysmi-lextudio==1.4.3
pysnmp-lextudio==6.1.2
pysnmpcrypto==0.0.4
requests==2.31.0
snimpy==1.0.2
urllib3==2.2.1
(snimpy-venv) $ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snimpy.manager import load, Manager
>>> load("SNMPv2-MIB")
>>> load("IF-MIB")
>>> m = Manager("10.1.1.1", "my_community", 2)
>>> for index, value in m.ifName.iteritems():
...     print(index, value)
...
1 dedicated-ha1
2 dedicated-ha2
...
(prints all the index+value pairs for the device)

--> Let's try again:

>>> for index, value in m.ifName.iteritems():
...     print(index, value)
...

Now it stays there, no progress. I waited for a couple of minutes, then pressed Ctrl-C:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/snimpy/manager.py", line 454, in iteritems
    for noid, result in self.session.walk(oid):
  File "/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/snimpy/snmp.py", line 333, in <genexpr>
    for noid, result in self.walkmore(oid)
                        ^^^^^^^^^^^^^^^^^^
  File "/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/snimpy/snmp.py", line 312, in walkmore
    return self._op(self._cmdgen.bulkCmd, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/snimpy/snmp.py", line 264, in _op
    errorIndication, errorStatus, errorIndex, varBinds = cmd(
                                                         ^^^^
  File "/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 100, in bulkCmd
    for errorIndication, errorStatus, errorIndex, varBinds in sync.bulkWalkCmd(
  File "/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/pysnmp/hlapi/asyncio/sync/cmdgen.py", line 679, in bulkWalkCmd
    result = loop.run_until_complete(run())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
^C    self.run_forever()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1884, in _run_once
    event_list = self._selector.select(timeout)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
>>> (Ctrl-D to quit the REPL)
Task was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<AsyncioDispatcher.handle_timeout() running at
/home/markku/temp/snimpy-venv/lib/python3.11/site-packages/pysnmp/carrier/asyncio/dispatch.py:62>
wait_for=<Future pending cb=[Task.task_wakeup()]>>

(snimpy-venv) $ pip list
Package            Version
------------------ --------
certifi            2024.2.2
cffi               1.16.0
charset-normalizer 3.3.2
cryptography       42.0.6
idna               3.7
Jinja2             3.1.3
MarkupSafe         2.1.5
pip                24.0
ply                3.11
pyasn1             0.6.0
pycparser          2.22
pysmi-lextudio     1.4.3
pysnmp-lextudio    6.1.2
pysnmpcrypto       0.0.4
requests           2.31.0
setuptools         66.1.1
snimpy             1.0.2
urllib3            2.2.1
wheel              0.43.0

@vincentbernat
Copy link
Owner

Humm, I didn't notice, but I have added pysnmp-lextudio < 6 as a restriction to master, but it's not part of 1.0.2. The API used by Snimpy was removed but it seems to have been added back on 6.0.9, but they seem to be buggy. Does it work if you force pysnmp-lextudio < 6?

@markkuleinio
Copy link
Author

(snimpy-venv) $ pip install -U "pysnmp-lextudio<6"
...
    Uninstalling pysnmp-lextudio-6.1.2:
      Successfully uninstalled pysnmp-lextudio-6.1.2
Successfully installed pysnmp-lextudio-5.0.34
(snimpy-venv) $ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snimpy.manager import load, Manager
>>> load("SNMPv2-MIB")
>>> load("IF-MIB")
>>> m = Manager("10.1.1.1", "my_community", 2)
>>> for index, value in m.ifName.iteritems():
...     print(index, value)
...
1 dedicated-ha1
2 dedicated-ha2
...

and now it seems to work, even when repeating the commands.

(snimpy-venv) $ pip list
Package            Version
------------------ --------
certifi            2024.2.2
cffi               1.16.0
charset-normalizer 3.3.2
cryptography       42.0.6
idna               3.7
Jinja2             3.1.3
MarkupSafe         2.1.5
pip                24.0
ply                3.11
pyasn1             0.6.0
pycparser          2.22
pysmi-lextudio     1.4.3
pysnmp-lextudio    5.0.34
pysnmpcrypto       0.0.4
requests           2.31.0
setuptools         66.1.1
snimpy             1.0.2
urllib3            2.2.1
wheel              0.43.0

@eduble
Copy link

eduble commented May 6, 2024

Same here. No more stucks with pysnmp-lextudio<6 it seems.

eduble added a commit to drakkar-lig/walt-python-packages that referenced this issue May 7, 2024
@vincentbernat
Copy link
Owner

vincentbernat commented May 9, 2024 via email

eduble added a commit to drakkar-lig/walt-python-packages that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants