GH-1684: Ensure that the time gets updated every pass if we're reading live traffic

This is necessary for e.g. packet sources that don't have a selectable
file descriptor. They'll always be ready on a very short timeout, but
won't necessarily have a packet to process. In these case, sometimes
the time won't get updated for a long time and timers don't function
correctly.
This commit is contained in:
Tim Wojtulewicz 2021-07-22 14:08:21 -07:00
parent 9383c926ad
commit 5fab986ccb

View file

@ -57,6 +57,7 @@ double first_timestamp = 0.0;
double current_wallclock = 0.0; double current_wallclock = 0.0;
double current_pseudo = 0.0; double current_pseudo = 0.0;
bool zeek_init_done = false; bool zeek_init_done = false;
bool time_updated = false;
RETSIGTYPE watchdog(int /* signo */) RETSIGTYPE watchdog(int /* signo */)
{ {
@ -133,6 +134,7 @@ RETSIGTYPE watchdog(int /* signo */)
void update_network_time(double new_network_time) void update_network_time(double new_network_time)
{ {
time_updated = true;
network_time = new_network_time; network_time = new_network_time;
PLUGIN_HOOK_VOID(HOOK_UPDATE_NETWORK_TIME, HookUpdateNetworkTime(new_network_time)); PLUGIN_HOOK_VOID(HOOK_UPDATE_NETWORK_TIME, HookUpdateNetworkTime(new_network_time));
} }
@ -287,6 +289,7 @@ void run_loop()
while ( iosource_mgr->Size() || while ( iosource_mgr->Size() ||
(BifConst::exit_only_after_terminate && ! terminating) ) (BifConst::exit_only_after_terminate && ! terminating) )
{ {
time_updated = false;
iosource_mgr->FindReadySources(&ready); iosource_mgr->FindReadySources(&ready);
#ifdef DEBUG #ifdef DEBUG
@ -327,6 +330,18 @@ void run_loop()
expire_timers(); expire_timers();
} }
// Ensure that the time gets updated every pass if we're reading live.
// This is necessary for e.g. packet sources that don't have a selectable
// file descriptor. They'll always be ready on a very short timeout, but
// won't necessarily have a packet to process. In these case, sometimes
// the time won't get updated for a long time and timers don't function
// correctly.
if ( (! time_updated && reading_live) )
{
update_network_time(util::current_time());
expire_timers();
}
event_mgr.Drain(); event_mgr.Drain();
processing_start_time = 0.0; // = "we're not processing now" processing_start_time = 0.0; // = "we're not processing now"