Compare commits

..

9 commits

Author SHA1 Message Date
Tim Wojtulewicz
a27cc89335 Remove checks for OpenSSL 1.x versions 2025-09-29 10:23:28 -07:00
Tim Wojtulewicz
686f100f0d Remove some additional LibreSSL checks 2025-09-29 10:23:28 -07:00
Arne Welzel
6af1459f5e Merge remote-tracking branch 'origin/topic/awelzel/4849-supervisor-signal-handle-tsan'
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
* origin/topic/awelzel/4849-supervisor-signal-handle-tsan:
  Supervisor: Make last_signal atomic to squelch data race
2025-09-29 18:04:49 +02:00
Tim Wojtulewicz
3c16ee9667 Update docs submodule [nomail] 2025-09-29 08:21:10 -07:00
Arne Welzel
31d7df915e Supervisor: Make last_signal atomic to squelch data race
When the stem process terminates and SIGCHLD is sent to the supervisor,
the signal might be handled by the main thread or any other threads that
aren't blocking SIGCHLD explicitly. Convert last_signal to a std::atomic<int>
such that non-main threads can safely set last_signal without triggering
data race as reported by TSAN. This doesn't make it less racy to work
last_signal, but it appears we only use it for debug printing anyhow and
another option might have been to just remove last_signal altogether.

Follow-up for #4849
2025-09-29 14:50:20 +02:00
Arne Welzel
3abc1116a1 Merge remote-tracking branch 'origin/topic/awelzel/zeromq-fix-block-subscribe-before-init'
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
* origin/topic/awelzel/zeromq-fix-block-subscribe-before-init:
  cluster/zeromq: Fix Cluster::subscribe() block if not initialized
2025-09-29 13:08:32 +02:00
Tim Wojtulewicz
0700427bac Merge remote-tracking branch 'origin/topic/vern/standalone-fixes2'
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
* origin/topic/vern/standalone-fixes2:
  Fixes for -O gen-standalone-C++ for tracking BiFs, lambdas, attribute types, and independent globals
2025-09-26 14:19:49 -07:00
Arne Welzel
01666df3d7 cluster/zeromq: Fix Cluster::subscribe() block if not initialized
If Cluster::init() hasn't been invoked yet, Cluster::subscribe() with the
ZeroMQ backend would block because the main_inproc socket didn't
yet have a connection from the child thread. Prevent this by connecting
the main and child socket pair at construction time.

This will queue the subscriptions and start processing them once the
child thread has started.
2025-09-25 18:58:35 +02:00
Vern Paxson
550c7eb0a7 Fixes for -O gen-standalone-C++ for tracking BiFs, lambdas, attribute types, and independent globals 2025-09-24 17:34:35 -07:00
11 changed files with 160 additions and 20 deletions

34
CHANGES
View file

@ -1,3 +1,37 @@
8.1.0-dev.612 | 2025-09-29 18:04:24 +0200
* Supervisor: Make last_signal atomic to squelch data race (Arne Welzel, Corelight)
When the stem process terminates and SIGCHLD is sent to the supervisor,
the signal might be handled by the main thread or any other threads that
aren't blocking SIGCHLD explicitly. Convert last_signal to a std::atomic<int>
such that non-main threads can safely set last_signal without triggering
data race as reported by TSAN. This doesn't make it less racy to work
last_signal, but it appears we only use it for debug printing anyhow and
another option might have been to just remove last_signal altogether.
Follow-up for #4849
8.1.0-dev.610 | 2025-09-29 08:21:01 -0700
* Update docs submodule [nomail] (Tim Wojtulewicz, Corelight)
8.1.0-dev.609 | 2025-09-29 13:08:15 +0200
* cluster/zeromq: Fix Cluster::subscribe() block if not initialized (Arne Welzel, Corelight)
If Cluster::init() hasn't been invoked yet, Cluster::subscribe() with the
ZeroMQ backend would block because the main_inproc socket didn't
yet have a connection from the child thread. Prevent this by connecting
the main and child socket pair at construction time.
This will queue the subscriptions and start processing them once the
child thread has started.
8.1.0-dev.607 | 2025-09-26 14:19:40 -0700
* Fixes for -O gen-standalone-C++ for tracking BiFs, lambdas, attribute types, and independent globals (Vern Paxson, Corelight)
8.1.0-dev.605 | 2025-09-26 11:19:17 -0700
* OpaqueVal, OCSP, X509: drop outdated LibreSSL guards to fix OpenBSD (Klemens Nanni)

View file

@ -1 +1 @@
8.1.0-dev.605
8.1.0-dev.612

2
doc

@ -1 +1 @@
Subproject commit 2731def9159247e6da8a3191783c89683363689c
Subproject commit 8f38ae2fd563314393eb1ca58c827d26e9966520

View file

@ -85,6 +85,7 @@ ZeroMQBackend::ZeroMQBackend(std::unique_ptr<EventSerializer> es, std::unique_pt
: ThreadedBackend("ZeroMQ", std::move(es), std::move(ls), std::move(ehs),
new zeek::detail::OnLoopProcess<ThreadedBackend, QueueMessage>(this, "ZeroMQ", onloop_queue_hwm)),
main_inproc(zmq::socket_t(ctx, zmq::socket_type::pair)),
child_inproc(zmq::socket_t(ctx, zmq::socket_type::pair)),
// Counters for block and drop metrics.
total_xpub_drops(
zeek::telemetry_mgr->CounterInstance("zeek", "cluster_zeromq_xpub_drops", {},
@ -94,7 +95,13 @@ ZeroMQBackend::ZeroMQBackend(std::unique_ptr<EventSerializer> es, std::unique_pt
"Number of received events dropped due to OnLoop queue full.")),
total_msg_errors(
zeek::telemetry_mgr->CounterInstance("zeek", "cluster_zeromq_msg_errors", {},
"Number of events with the wrong number of message parts.")) {}
"Number of events with the wrong number of message parts.")) {
// Establish the socket connection between main thread and child thread
// already in the constructor. This allows Subscribe() and Unsubscribe()
// calls to be delayed until DoInit() was called.
main_inproc.bind("inproc://inproc-bridge");
child_inproc.connect("inproc://inproc-bridge");
}
ZeroMQBackend::~ZeroMQBackend() {
try {
@ -169,10 +176,11 @@ void ZeroMQBackend::DoTerminate() {
ctx.shutdown();
// Close the sockets that are used from the main thread,
// the remaining sockets were closed by self_thread during
// shutdown already.
// the remaining sockets except for the child_inproc one
// were closed by self_thread during shutdown already.
log_push.close();
main_inproc.close();
child_inproc.close();
ZEROMQ_DEBUG("Closing ctx");
ctx.close();
@ -197,7 +205,6 @@ bool ZeroMQBackend::DoInit() {
xpub = zmq::socket_t(ctx, zmq::socket_type::xpub);
log_push = zmq::socket_t(ctx, zmq::socket_type::push);
log_pull = zmq::socket_t(ctx, zmq::socket_type::pull);
child_inproc = zmq::socket_t(ctx, zmq::socket_type::pair);
xpub.set(zmq::sockopt::linger, linger_ms);
@ -286,10 +293,6 @@ bool ZeroMQBackend::DoInit() {
//
// https://funcptr.net/2012/09/10/zeromq---edge-triggered-notification/
// Setup connectivity between main and child thread.
main_inproc.bind("inproc://inproc-bridge");
child_inproc.connect("inproc://inproc-bridge");
// Thread is joined in backend->DoTerminate(), backend outlives it.
self_thread = std::thread([](auto* backend) { backend->Run(); }, this);
@ -634,7 +637,6 @@ void ZeroMQBackend::Run() {
// Called when Run() terminates.
auto deferred_close = util::Deferred([this]() {
child_inproc.close();
xpub.close();
xsub.close();
log_pull.close();

View file

@ -83,9 +83,22 @@ void CPPCompile::Compile(bool report_uncompilable) {
accessed_globals.insert(g);
for ( auto& ag : pf->AllGlobals() )
all_accessed_globals.insert(ag);
for ( auto& l : pf->Lambdas() )
// We might not have profiled this previously if none
// of the functions refer to the global. This can
// happen for example for a global "const" table that's
// made available for external lookup use.
pfs->ProfileLambda(l);
}
}
for ( auto& g : pfs->BiFGlobals() )
all_accessed_globals.insert(g);
for ( auto& t : pfs->MainTypes() )
if ( obj_matches_opt_files(t) == AnalyzeDecision::SHOULD )
rep_types.insert(TypeRep(t));
for ( auto& l : pfs->Lambdas() )
if ( obj_matches_opt_files(l) == AnalyzeDecision::SHOULD )
accessed_lambdas.insert(l);

View file

@ -622,6 +622,20 @@ ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred
ComputeSideEffects();
}
void ProfileFuncs::ProfileLambda(const LambdaExpr* l) {
if ( lambdas.contains(l) )
return;
lambdas.insert(l);
pending_exprs.push_back(l);
do
DrainPendingExprs();
while ( ! pending_exprs.empty() );
AnalyzeLambdaProfile(l);
}
bool ProfileFuncs::IsTableWithDefaultAggr(const Type* t) {
auto analy = tbl_has_aggr_default.find(t);
if ( analy != tbl_has_aggr_default.end() )
@ -848,14 +862,22 @@ void ProfileFuncs::ComputeBodyHashes(std::vector<FuncInfo>& funcs) {
ComputeProfileHash(f.ProfilePtr());
}
for ( auto& l : lambdas ) {
auto pf = ExprProf(l);
func_profs[l->PrimaryFunc().get()] = pf;
lambda_primaries[l->Name()] = l->PrimaryFunc().get();
for ( auto& l : lambdas )
AnalyzeLambdaProfile(l);
}
if ( compute_func_hashes || ! pf->HasHashVal() )
ComputeProfileHash(pf);
}
void ProfileFuncs::AnalyzeLambdaProfile(const LambdaExpr* l) {
if ( processed_lambdas.contains(l) )
return;
processed_lambdas.insert(l);
auto pf = ExprProf(l);
func_profs[l->PrimaryFunc().get()] = pf;
lambda_primaries[l->Name()] = l->PrimaryFunc().get();
if ( compute_func_hashes || ! pf->HasHashVal() )
ComputeProfileHash(pf);
}
void ProfileFuncs::ComputeProfileHash(std::shared_ptr<ProfileFunc> pf) {

View file

@ -366,6 +366,10 @@ public:
ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred, bool compute_func_hashes,
bool full_record_hashes);
// Used to profile additional lambdas that (potentially) weren't part
// of the overall function profiling.
void ProfileLambda(const LambdaExpr* l);
// The following accessors provide a global profile across all of
// the (non-skipped) functions in "funcs". See the comments for
// the associated member variables for documentation.
@ -449,6 +453,9 @@ protected:
// Compute hashes to associate with each function
void ComputeBodyHashes(std::vector<FuncInfo>& funcs);
// For a given lambda, completes analysis of its profile.
void AnalyzeLambdaProfile(const LambdaExpr* l);
// Compute the hash associated with a single function profile.
void ComputeProfileHash(std::shared_ptr<ProfileFunc> pf);
@ -540,6 +547,10 @@ protected:
// And for lambda's.
std::unordered_set<const LambdaExpr*> lambdas;
// Lambdas that we have already processed. An optimization to avoid
// unnecessary work.
std::unordered_set<const LambdaExpr*> processed_lambdas;
// Names of generated events.
std::unordered_set<std::string> events;

View file

@ -415,7 +415,7 @@ static ForkResult fork_with_stdio_redirect(const char* where) {
void Supervisor::HandleChildSignal() {
if ( last_signal >= 0 ) {
DBG_LOG(DBG_SUPERVISOR, "Supervisor received signal %d", last_signal);
DBG_LOG(DBG_SUPERVISOR, "Supervisor received signal %d", last_signal.load());
last_signal = -1;
}

View file

@ -3,6 +3,7 @@
#pragma once
#include <sys/types.h>
#include <atomic>
#include <chrono>
#include <map>
#include <memory>
@ -323,7 +324,7 @@ private:
Config config;
pid_t stem_pid;
int last_signal = -1;
std::atomic<int> last_signal = -1;
std::unique_ptr<detail::PipePair> stem_pipe;
detail::LineBufferedPipe stem_stdout;
detail::LineBufferedPipe stem_stderr;

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
test(), 42

View file

@ -0,0 +1,55 @@
# @TEST-DOC: Regression test Cluster::subscribe() blocking if called in a high-priority zeek_init() handler
#
# @TEST-REQUIRES: have-zeromq
#
# @TEST-GROUP: cluster-zeromq
#
# @TEST-PORT: XPUB_PORT
# @TEST-PORT: XSUB_PORT
# @TEST-PORT: LOG_PULL_PORT
#
# @TEST-EXEC: cp $FILES/zeromq/cluster-layout-simple.zeek cluster-layout.zeek
# @TEST-EXEC: cp $FILES/zeromq/test-bootstrap.zeek zeromq-test-bootstrap.zeek
#
# @TEST-EXEC: zeek --parse-only ./manager.zeek ./worker.zeek
#
# @TEST-EXEC: btest-bg-run manager "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=manager zeek -b ../manager.zeek >out"
# @TEST-EXEC: btest-bg-run worker "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=worker-1 zeek -b ../worker.zeek >out"
#
# @TEST-EXEC: btest-bg-wait 30
# @TEST-EXEC: btest-diff ./manager/out
# @TEST-START-FILE common.zeek
@load ./zeromq-test-bootstrap
global test: event(c: count) &is_used;
# @TEST-END-FILE
# @TEST-START-FILE manager.zeek
@load ./common.zeek
event zeek_init() &priority=1000000
{
Cluster::subscribe("test.early");
}
event test(c: count)
{
print "test()", c;
}
event Cluster::node_down(name: string, id: string)
{
terminate();
}
# @TEST-END-FILE
# @TEST-START-FILE worker.zeek
@load ./common.zeek
event Cluster::node_up(name: string, id: string)
{
Cluster::publish("test.early", test, 42);
terminate();
}
# @TEST-END-FILE