etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
577 stars 199 forks source link

Trap sent twice #219

Open andreimircescu opened 5 years ago

andreimircescu commented 5 years ago

When I try to send a trap, sometimes I see the trap on the server twice or three times.

send_trap.log has the log output of a trap sent twice. send_trap.log

One thing that caught my eye is the fact that it does 2 handle_writes.

The server i'm using is this --> https://github.com/etingof/pysnmp/blob/release-4.4.7/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py

andreimircescu commented 5 years ago

One extra thing, if i send to another destination with the same security level and credentials, it will receive just one trap packet. L.E If i restart the agent, it goes back to one packet.

etingof commented 5 years ago

Interesting... Could you share the code that sends these TRAPs? Or complete debug (if it does not have anything confidential)?

Generally speaking, TRAPs could be sent to multiple destinations tagged by the tags belonging to a tag list. This is implemented in pysnmp, may be somehow TRAP destinations get accumulated under the same tag list....

andreimircescu commented 5 years ago

I will try to generate a complete debug but the thing is that I don't know yet what triggers it.

I use hlapi(http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.html) with some wrappers on top of it. The only entity that binds them is the snmp engine, I used one for all the traps that I sent. The sendNotification api is called from multiple threads but it shouldn't be any issue with this unless there are some thread locals somewhere. sendNotification API is guarded with a lock so there's no concurrency.

If i'm creating the snmp engine every time, I don't see the issue but i'm not 100% sure yet.