snmp: fix async handling#349
Conversation
WalkthroughThe changes refactor the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant SNMPServer
participant SNMPEngine
Client->>SNMPServer: _snmp_set(state)
SNMPServer->>SNMPServer: _setup_event_loop()
SNMPServer->>SNMPServer: _create_snmp_callback(result, event)
SNMPServer->>SNMPEngine: _run_snmp_dispatcher(event)
SNMPEngine-->>SNMPServer: SNMP response arrives
SNMPServer->>SNMPServer: Callback updates result and sets event
SNMPServer-->>Client: Return SNMP operation result
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
🔇 Additional comments (6)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for jumpstarter-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| except RuntimeError: | ||
| loop = asyncio.new_event_loop() |
There was a problem hiding this comment.
each time as we are not in the context of an event loop
|
|
||
| snmp_engine.open_dispatcher(self.timeout) | ||
| snmp_engine.close_dispatcher() | ||
| dispatcher_task = loop.create_task(self._run_snmp_dispatcher(snmp_engine, response_received)) |
There was a problem hiding this comment.
I wonder if this dispatcher should be started before we send?
Is it used to receive the response?
I know it was like this before, but I wonder if it works just because it sets up very quickly before the response arrives?
Haven't checked the library docs though ...
There was a problem hiding this comment.
def open_dispatcher(self, timeout: float = 0):
"""
Open the dispatcher used by SNMP engine.
This method is called when SNMP engine is ready to process SNMP
messages. It opens the dispatcher and starts processing incoming
messages.
"""
if self.transport_dispatcher:
self.transport_dispatcher.run_dispatcher(timeout)In lib's docs they always call it last
https://github.com/lextudio/pysnmp/blob/8ddc451816c85d7ef238eb9cfdd5a74c114fae28/examples/v3arch/asyncio/manager/cmdgen/v2c-set.py#L12
There was a problem hiding this comment.
ahh, the dispatcher sends the messages and collects answers, ok :)
|
Thanks for handling this!!! :-) |
Have the callback fire an event to avoid waiting too long Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Have the callback fire an event to avoid waiting too long
Summary by CodeRabbit
New Features
Refactor