Fix race condition in scripts.base.frameworks.input.invalid*

The invalidset and invalidtext tests loaded an input file via table
and event reads, in parallel. On FreeBSD this triggers an occasional
reordering of messages coming out of the reader thread vs the input
managers. This commit makes the table and event reads sequential,
avoiding the race.
This commit is contained in:
Christian Kreibich 2021-07-09 17:17:49 -07:00
parent 8bcaa64d8f
commit 4e75662963
2 changed files with 14 additions and 2 deletions

View file

@ -50,13 +50,19 @@ event zeek_init()
outfile = open("../out");
# first read in the old stuff into the table...
Input::add_table([$source="../input.log", $name="ssh", $error_ev=handle_our_errors, $idx=Idx, $val=Val, $destination=servers]);
Input::add_event([$source="../input.log", $name="sshevent", $error_ev=handle_our_errors_event, $fields=Val, $want_record=T, $ev=line]);
}
event Input::end_of_data(name: string, source:string)
{
++endcount;
# ... and when we're done, move to reading via events.
# This makes the reads sequential, avoding races in the output.
if ( endcount == 1 )
{
Input::add_event([$source="../input.log", $name="sshevent", $error_ev=handle_our_errors_event, $fields=Val, $want_record=T, $ev=line]);
}
if ( endcount == 2 )
{
print outfile, servers;

View file

@ -51,13 +51,19 @@ event zeek_init()
outfile = open("../out");
# first read in the old stuff into the table...
Input::add_table([$source="../input.log", $name="ssh", $error_ev=handle_our_errors, $idx=Idx, $val=Val, $destination=servers]);
Input::add_event([$source="../input.log", $name="sshevent", $error_ev=handle_our_errors_event, $fields=Val, $want_record=T, $ev=line]);
}
event Input::end_of_data(name: string, source:string)
{
++endcount;
# ... and when we're done, move to reading via events.
# This makes the reads sequential, avoding races in the output.
if ( endcount == 1 )
{
Input::add_event([$source="../input.log", $name="sshevent", $error_ev=handle_our_errors_event, $fields=Val, $want_record=T, $ev=line]);
}
if ( endcount == 2 )
{
print outfile, servers;