GH-938: fix IO loop iterations sometimes skipping offline pcap sources

This commit is contained in:
Jon Siwek 2020-04-29 11:31:01 -07:00
parent fda9498276
commit 1b190906c7
3 changed files with 39 additions and 4 deletions

View file

@ -136,6 +136,8 @@ void Manager::FindReadySources(std::vector<IOSource*>* ready)
if ( iosource->IsOpen() )
{
double next = iosource->GetNextTimeout();
bool added = false;
if ( timeout == -1 || ( next >= 0.0 && next < timeout ) )
{
timeout = next;
@ -146,14 +148,30 @@ void Manager::FindReadySources(std::vector<IOSource*>* ready)
// we don't want things in the vector passed into Poll() or it'll end
// up inserting duplicates.
if ( timeout == 0 && ! time_to_poll )
{
added = true;
ready->push_back(timeout_src);
}
}
// Avoid calling Poll() if we can help it since on very high-traffic
// networks, we spend too much time in Poll() and end up dropping packets.
if ( ! time_to_poll && iosource == pkt_src && pkt_src->IsLive() )
if ( iosource == pkt_src && ! added )
{
if ( pkt_src->IsLive() )
{
if ( ! time_to_poll )
// Avoid calling Poll() if we can help it since on very
// high-traffic networks, we spend too much time in
// Poll() and end up dropping packets.
ready->push_back(pkt_src);
}
else
{
if ( ! pseudo_realtime )
// A pcap file is always ready to process.
ready->push_back(pkt_src);
}
}
}
}
DBG_LOG(DBG_MAINLOOP, "timeout: %f ready size: %zu time_to_poll: %d\n",

View file

@ -0,0 +1,2 @@
0.0
1362692526.869344

View file

@ -0,0 +1,15 @@
# @TEST-EXEC: zeek -b -r $TRACES/http/get.trace %INPUT >out
# @TEST-EXEC: btest-diff out
event my_init()
{
# Expect time to be initialized (PktSrc was processed at least once).
print network_time();
}
event zeek_init()
{
# Expect time to be zero
print network_time();
schedule 0sec { my_init() };
}