-
Notifications
You must be signed in to change notification settings - Fork 950
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
bugfix: avoid data race in set exec exit status #2152
Conversation
The result may error depend on which goroutine run last
|
@@ -77,7 +77,6 @@ func (mgr *ContainerManager) StartExec(ctx context.Context, execid string, attac | |||
exitCode := 126 | |||
execConfig.ExitCode = int64(exitCode) | |||
} | |||
mgr.ExecProcesses.Put(execid, execConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execConfig is a pointer, no need to use mgr.ExecProcesses.Put again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this part, I want to raise proposal that we should deep copy data from manager data store to avoid the data race. But it will introduce the complicated.
Codecov Report
@@ Coverage Diff @@
## master #2152 +/- ##
==========================================
- Coverage 64.46% 39.5% -24.96%
==========================================
Files 209 209
Lines 16680 16678 -2
==========================================
- Hits 10752 6589 -4163
- Misses 4599 9053 +4454
+ Partials 1329 1036 -293
|
logrus.Errorf("failed to execute the exec exit hooks: %v", err) | ||
break | ||
// run hook if not got fail here | ||
if err := <-fail; err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get the real exit code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When fails here, we got a empty(meaningless) exit status, that means exit code is zero.
test/cli_exec_test.go
Outdated
|
||
// test a 'executable file not found' fail should get exit code 126 | ||
name = "TestExecFailCode" | ||
command.PouchRun("run", "-d", "--name", name, busyboxImage, "top").Assert(c, icmd.Success) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you update the case description, since there are two cases here?
there are two goroutines response for changed exec config information, if exec process got error, data race appears, exec exit hook runs in a goroutine, it modify exec exit status, StartExec also modify exec exit status in another goroutine since error happend. Fix it by only one place can modify exec exit status. Signed-off-by: Ace-Tang <aceapril@126.com>
fail with
|
func (suite *PouchExecSuite) TestExecFail(c *check.C) { | ||
name := "TestExecFail" | ||
res := command.PouchRun("run", "-d", "--name", name, "-u", name, busyboxImage, "top") | ||
defer DelContainerForceMultyTime(c, name) | ||
c.Assert(res.Stderr(), check.NotNil) | ||
|
||
// test a 'executable file not found' fail should get exit code 126. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we split it into two cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just keep this ?
@@ -77,7 +77,6 @@ func (mgr *ContainerManager) StartExec(ctx context.Context, execid string, attac | |||
exitCode := 126 | |||
execConfig.ExitCode = int64(exitCode) | |||
} | |||
mgr.ExecProcesses.Put(execid, execConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this part, I want to raise proposal that we should deep copy data from manager data store to avoid the data race. But it will introduce the complicated.
@fuweid, deep copy may need, but for this case, we should keep the data race from the logic, deep copy won't avoid this. |
LGTM |
there are two goroutines response for changed exec config information,
if exec process got error, data race appears, exec exit hook runs in a
goroutine, it modify exec exit status, StartExec also modify exec exit
status in another goroutine since error happend. Fix it by only one
place can modify exec exit status.
Signed-off-by: Ace-Tang aceapril@126.com
Ⅰ. Describe what this PR did
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews