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

exception - queue full in nlsocket - async_recv() #1034

Open
laplasz opened this issue Sep 28, 2022 · 4 comments
Open

exception - queue full in nlsocket - async_recv() #1034

laplasz opened this issue Sep 28, 2022 · 4 comments

Comments

@laplasz
Copy link

laplasz commented Sep 28, 2022

example code:

with IPRoute() as ipr:
# With IPRoute objects you have to call bind() manually
ipr.bind(async_cache=True)
while True:
try:
for message in ipr.get():
<....>
except OSError as e:
raise e

callstack:
for message in ipr.get():
File "/usr/local/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 394, in get
return tuple(self._genlm_get(*argv, **kwarg))
File "/usr/local/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 788, in get
data = self.recv_ft(bufsize)
File "/usr/local/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 1067, in recv_plugin
raise data_in
File "/usr/local/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 580, in async_recv
self.buffer_queue.put_nowait(data)
File "/usr/lib64/python3.9/queue.py", line 191, in put_nowait
return self.put(item, block=False)
File "/usr/lib64/python3.9/queue.py", line 137, in put
raise Full

@svinota
Copy link
Owner

svinota commented Sep 29, 2022

Looks like the parser doesn't manage to handle the packet flow.

Possible solutions:

1. increase the buffer queue

from pyroute2 import config, IPRoute
config.async_qsize = X
ipr = IPRoute()

# or
from pyroute2 import IPRoute
ipr = IPRoute(async_qsize=X)

Where X is the queue max size, by default 4096. The socket uses 64K buffers for each recv_into(), so consider memory usage as well.

2. use a custom parser

IPRoute objects have .marshal to run parsers on incoming messages.

IPRoute.marshal.msg_map = {msg_type: parser}
IPRoute.marshal.seq_map = {sequence_number: parser}

More on parsers and how to run own implementations: https://docs.pyroute2.org/parser.html

@LuiGuest
Copy link

Looks like the parser doesn't manage to handle the packet flow.

Possible solutions:

1. increase the buffer queue

from pyroute2 import config, IPRoute
config.async_qsize = X
ipr = IPRoute()

# or
from pyroute2 import IPRoute
ipr = IPRoute(async_qsize=X)

Where X is the queue max size, by default 4096. The socket uses 64K buffers for each recv_into(), so consider memory usage as well.

2. use a custom parser

IPRoute objects have .marshal to run parsers on incoming messages.

IPRoute.marshal.msg_map = {msg_type: parser}
IPRoute.marshal.seq_map = {sequence_number: parser}

More on parsers and how to run own implementations: https://docs.pyroute2.org/parser.html

As I understand this could happen due to temporal event storm, in which case the parser will lose pace against the socket reader, and the queue will get full.
Is there a way to somehow instruct the API to restrict which events it should deliver via the socket?

@svinota
Copy link
Owner

svinota commented Sep 30, 2022

@LuiGuest there are three ways setting up that:

  1. Using groups -- ipr.bind(groups=...), see pyroute2.netlink.rtnl.RTMGRP_* (becomes deprecated in the Linux kernel, but still used by default in the library)
  2. Using membership -- ipr.add_membership(...) / ipr.drop_membership(...), see pyroute2.netlink.rtnl.RTNLGRP_*
  3. Using custom parsers and assigning to particular message types (ipr.marshal.msg_map) or sequence numbers (ipr.marshal.seq_map)

...

  1. and 2. will instruct the kernel not to send some message types, while 3. makes pyroute2 to drop received messages w/o parsing them (by the default parser)

@LuiGuest
Copy link

  1. RTMGRP_

Thank You a lot for your help!

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