Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swaglog: delay creating zmq socket to first use - fix modeld crash in sim #24271

Merged
merged 5 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions selfdrive/common/statlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class StatlogState : public LogState {
static StatlogState s = {};

static void log(const char* metric_type, const char* metric, const char* fmt, ...) {
if (!s.initialized) s.initialize();
gijskoning marked this conversation as resolved.
Show resolved Hide resolved

char* value_buf = nullptr;
va_list args;
va_start(args, fmt);
Expand Down
4 changes: 1 addition & 3 deletions selfdrive/common/swaglog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class SwaglogState : public LogState {
public:
SwaglogState() : LogState("ipc:///tmp/logmessage") {}

bool initialized = false;
json11::Json::object ctx_j;

inline void initialize() {
LogState::initialize();
gijskoning marked this conversation as resolved.
Show resolved Hide resolved
ctx_j = json11::Json::object {};
print_level = CLOUDLOG_WARNING;
const char* print_lvl = getenv("LOGPRINT");
Expand Down Expand Up @@ -56,8 +56,6 @@ class SwaglogState : public LogState {
} else {
ctx_j["device"] = "pc";
}

initialized = true;
}
};

Expand Down
12 changes: 10 additions & 2 deletions selfdrive/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,18 @@ void update_max_atomic(std::atomic<T>& max, T const& value) {

class LogState {
public:
bool initialized = false;
std::mutex lock;
void *zctx;
void *sock;
int print_level;
const char* endpoint;

LogState(const char* endpoint) {
LogState(const char* _endpoint) {
endpoint = _endpoint;
}

inline void initialize() {
zctx = zmq_ctx_new();
sock = zmq_socket(zctx, ZMQ_PUSH);

Expand All @@ -182,7 +188,9 @@ class LogState {
zmq_setsockopt(sock, ZMQ_LINGER, &timeout, sizeof(timeout));

zmq_connect(sock, endpoint);
};
initialized = true;
}

~LogState() {
zmq_close(sock);
gijskoning marked this conversation as resolved.
Show resolved Hide resolved
zmq_ctx_destroy(zctx);
Expand Down