I went deep down the rabbit hole to get to the bottom of this one, understanding BER specs, etc. - I can almost fully parse SNMP packets in my head from reading hex dumps at this point ;)
I had the SNMP agent running on an ESP32 project, polling it via Observium. All was looking good!
Then after adding some additional handlers and/or changing some response lengths for said handlers, Observium appeared to hang when doing a discovery. Further digging revealed that it was snmpbulkwalk holding up the discovery operation. Capturing the exchange with Wireshark shed more light on it.
The solution ended up being simple - a couple of instances where conditional checks needed to be changed in encode_ber_length_integer() and encode_ber_length_integer_count()
Changing (integer > 256) to (integer >= 256) in each resolved the issue.
I've fixed it in my fork:
N1IOX@291e3d6