mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
option.bif: Short-circuit option changes when terminating
Due to the asynchronous behavior of the input framework and broker communication, change handlers were previously called even after zeek_done() event processing completed and also broker shutdown. Accessing broker store handles within change handlers this late triggered invalid Broker store handle messages: error in ././my_option_store.zeek, line 13: invalid Broker store handle (Broker::put(Test::store, to_any_coercemy_option, to_any_coerceTest::new_value, 0 secs) and broker::store::{}) Fixes #2010
This commit is contained in:
parent
28081d1efa
commit
11cde53373
4 changed files with 45 additions and 0 deletions
4
NEWS
4
NEWS
|
@ -41,6 +41,10 @@ Changed Functionality
|
||||||
- The default logging directory is now set globally across all log
|
- The default logging directory is now set globally across all log
|
||||||
writers through ``Log::default_logdir``.
|
writers through ``Log::default_logdir``.
|
||||||
|
|
||||||
|
- Calling `Option::set()` when Zeek is terminating is now a noop and returns `F`.
|
||||||
|
This prevents callbacks into script-land through change handlers when parts
|
||||||
|
of the environment have already been torn down.
|
||||||
|
|
||||||
Deprecated Functionality
|
Deprecated Functionality
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ module Option;
|
||||||
static bool call_option_handlers_and_set_value(zeek::StringVal* name, const zeek::detail::IDPtr& i,
|
static bool call_option_handlers_and_set_value(zeek::StringVal* name, const zeek::detail::IDPtr& i,
|
||||||
zeek::ValPtr val, zeek::StringVal* location)
|
zeek::ValPtr val, zeek::StringVal* location)
|
||||||
{
|
{
|
||||||
|
// when shutting down, don't call back into script land handlers as
|
||||||
|
// these may use resources that have already been shutdown.
|
||||||
|
if ( zeek::run_state::terminating )
|
||||||
|
return false;
|
||||||
|
|
||||||
if ( i->HasOptionHandlers() )
|
if ( i->HasOptionHandlers() )
|
||||||
{
|
{
|
||||||
for ( auto handler_function : i->GetOptionHandlers() )
|
for ( auto handler_function : i->GetOptionHandlers() )
|
||||||
|
|
7
testing/btest/Baseline/core.option-zeek-done/.stdout
Normal file
7
testing/btest/Baseline/core.option-zeek-done/.stdout
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
Initial value, T
|
||||||
|
Value of testbool changed from T to F (zeek_is_terminating=F)
|
||||||
|
Next value, F
|
||||||
|
Next changed, T
|
||||||
|
Final value, F
|
||||||
|
Final changed, F
|
29
testing/btest/core/option-zeek-done.zeek
Normal file
29
testing/btest/core/option-zeek-done.zeek
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# @TEST-DOC: Ensure change handlers do not run when terminating by trying to change an option during zeek_done()
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT
|
||||||
|
# @TEST-EXEC: btest-diff .stdout
|
||||||
|
|
||||||
|
export {
|
||||||
|
option testbool: bool = T;
|
||||||
|
}
|
||||||
|
|
||||||
|
function option_changed(ID: string, new_value: bool): bool {
|
||||||
|
print fmt("Value of %s changed from %s to %s (zeek_is_terminating=%s)", ID, testbool, new_value, zeek_is_terminating());
|
||||||
|
return new_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
print "Initial value", testbool;
|
||||||
|
Option::set_change_handler("testbool", option_changed);
|
||||||
|
local changed = Option::set("testbool", F);
|
||||||
|
print "Next value", testbool;
|
||||||
|
print "Next changed", changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_done()
|
||||||
|
{
|
||||||
|
local changed = Option::set("testbool", T);
|
||||||
|
print "Final value", testbool;
|
||||||
|
print "Final changed", changed;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue