Hi
I have a script that collects SNMP data from lots of devices using AnyEvent::SNMP. It works well, but I have noticed that it hangs if $session->get_table throws an error. I've tried various ways to handle the error and end the request but nothing seems to work. I'm guessing that it hangs because $cv->end is not called because the error is not handled.
Here is a snippet of code that explains it. I've trawled through many AnyEvent examples but can't seem to find anything to help so hoping someone can help. The program is complex so i've provided only the relevant blocks to illustrate:

my $cv = AnyEvent->condvar; foreach my $host (sort keys %hosts) { my ($session, $error) = Net::SNMP->session ( -hostname => $host, -community => $host_snmp_community, -version => $host_snmp_version, -nonblocking => 1, ) or $log->error("Error creating SNMP session for $host commun +ity:".$host_snmp_community." version:".$host_snmp_version); foreach my $table_oid (sort keys %snmp_tables) { $cv->begin; $session->get_table( -baseoid => $snmp_table, # can't use this option for snmp v1 #-maxrepetitions => 1, -callback => sub{ $hosts{$host}{oid_ +results_table}->{$snmp_table}= &snmp_collect(@_); $cv->end; } ) } } $cv->recv;

In reply to Error handling in AnyEvent::SNMP by mmoorreett

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.