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

Fix race in syscallWatcher #431

Merged
merged 2 commits into from
Dec 19, 2018

Conversation

sesmith177
Copy link
Contributor

This PR fixes two issues:

  1. If the syscallWatcher function is started in a goroutine, the goroutine remains around for the length of timeout.SyscallWatcher (4 minutes). So a longrunning process can accumulate goroutines if it makes many syscalls that use the syscallWatcher in a 4 minute span.

  2. There is a race condition where both the syscallWatcher goroutine and the main function access the completed variable. This will cause any test suites that:

    • run under go test -race
    • call into hcsshim
    • last longer than 4 minutes

to fail due to the race detector. An easy way to reproduce is:

completed := false
go syscallWatcher(context, &completed)
time.Sleep(timeout.SyscallWatcher + 5 * time.Second)
completed = true	

This PR fixes the issue by using a context.Context object to handle the timeout

Signed-off-by: Yechiel Kalmenson ykalmenson@pivotal.io

Signed-off-by: Yechiel Kalmenson <ykalmenson@pivotal.io>
@msftclas
Copy link

msftclas commented Dec 18, 2018

CLA assistant check
All CLA requirements met.

@jterry75
Copy link
Contributor

#395

@jterry75
Copy link
Contributor

Thank you this is great!

@jterry75
Copy link
Contributor

LGTM. @kevpar - PTAL

Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments but overall LGTM.

// go syscallWatcher(context, &completed)
// <syscall>
// completed = true
// sysycallWatcher(logContext, func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo "sysycall"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, fixed :)


func watchFunc(ctx context.Context, logContext logrus.Fields) {
select {
case <-ctx.Done():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a select statement here, since there is only one case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct that with a single case the code can be written inline. But this is a golang pattern so it doesn't bother me either way. Up to you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's the pattern we've seen in the documentation. Let up know if you want us to change it.

@jterry75 jterry75 merged commit 218ab38 into microsoft:master Dec 19, 2018
arjun024 pushed a commit to cloudfoundry/winc that referenced this pull request Jan 29, 2019
Many transitive dependencies have been updated.

This update includes our [PR](microsoft/hcsshim#431)
to the syscall watcher

All the tests pass with no major API changes

Signed-off-by: Arjun Sreedharan <asreedharan@pivotal.io>
arjun024 pushed a commit to cloudfoundry/winc that referenced this pull request Jan 29, 2019
Uses greenhouse-org/hcsshim, branch upstream-v0.8.5-mod.
This contains all commits from Microsoft/hcsshim v.0.8.5 +
commits made by our team to the fork.

Many transitive dependencies have been updated.

This update includes our PR (microsoft/hcsshim#431)
to the syscall watcher

All the tests pass with no major API changes

Signed-off-by: Arjun Sreedharan <asreedharan@pivotal.io>
arjun024 pushed a commit to cloudfoundry/winc that referenced this pull request Feb 5, 2019
Uses greenhouse-org/hcsshim, branch upstream-v0.8.5-mod.
This contains all commits from Microsoft/hcsshim v.0.8.5 +
commits made by our team to the fork.

Many transitive dependencies have been updated.

This update includes our PR (microsoft/hcsshim#431)
to the syscall watcher

All the tests pass with no major API changes

Signed-off-by: Arjun Sreedharan <asreedharan@pivotal.io>
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants