Skip to content

Commit

Permalink
rework worker protection (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Dec 26, 2023
1 parent 2a15910 commit 16eb03b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/CMQWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,23 @@ class CMQWorker {
env.assign(name, msg2r(std::move(*it), true));
}

auto cmd = msg2r(std::move(msgs[1]), true);
SEXP cmd, eval, time, mem;
PROTECT(cmd = msg2r(std::move(msgs[1]), true));
int err = 0;
SEXP eval = PROTECT(R_tryEvalSilent(Rcpp::as<Rcpp::List>(cmd)[0], env, &err));
PROTECT(eval = R_tryEvalSilent(Rcpp::as<Rcpp::List>(cmd)[0], env, &err));
if (err) {
auto cmq = Rcpp::Environment::namespace_env("clustermq");
Rcpp::Function wrap_error = cmq["wrap_error"];
eval = wrap_error(cmd);
UNPROTECT(1);
PROTECT(eval = wrap_error(cmd));
}
PROTECT(time = proc_time());
PROTECT(mem = gc());
sock.send(int2msg(wlife_t::active), zmq::send_flags::sndmore);
sock.send(r2msg(proc_time()), zmq::send_flags::sndmore);
sock.send(r2msg(gc()), zmq::send_flags::sndmore);
sock.send(r2msg(time), zmq::send_flags::sndmore);
sock.send(r2msg(mem), zmq::send_flags::sndmore);
sock.send(r2msg(eval), zmq::send_flags::none);
UNPROTECT(1);
UNPROTECT(4);
return true;
}

Expand Down

0 comments on commit 16eb03b

Please sign in to comment.