-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
nsexec logging race #3119
Labels
Comments
As the production rarely uses debug, in practice this is fixed by b1bc762 |
Another possible solution is something like this diff --git a/libcontainer/nsenter/nsexec.c b/libcontainer/nsenter/nsexec.c
index 8199faf3..0c9eca00 100644
--- a/libcontainer/nsenter/nsexec.c
+++ b/libcontainer/nsenter/nsexec.c
@@ -142,7 +142,7 @@ int setns(int fd, int nstype)
static void write_log(const char *level, const char *format, ...)
{
- char *message = NULL, *stage = NULL;
+ char *message = NULL, *stage = NULL, *json = NULL;
va_list args;
int ret;
@@ -164,11 +164,16 @@ static void write_log(const char *level, const char *format, ...)
if (ret < 0)
goto out;
- dprintf(logfd, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
+ ret = asprintf(&json, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
+ if (ret < 0)
+ goto out;
+
+ write(logfd, json, ret);
out:
free(message);
free(stage);
+ free(json);
}
/* XXX: This is ugly. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As reported in https://kubernetes.slack.com/archives/CAZH62UR1/p1627584431224800
What we see here is runc failed to decode JSON log message from runc init's nsexec.c. The messages are:
Looks like the code hit a jackpot of a debug log race between the parent at
runc/libcontainer/nsenter/nsexec.c
Lines 820 to 821 in d962bb0
and the first child at
runc/libcontainer/nsenter/nsexec.c
Line 1021 in d962bb0
Cc @cyphar
The text was updated successfully, but these errors were encountered: