-
Notifications
You must be signed in to change notification settings - Fork 264
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package hcs | ||
|
||
import ( | ||
"time" | ||
"context" | ||
|
||
"github.com/Microsoft/hcsshim/internal/logfields" | ||
"github.com/Microsoft/hcsshim/internal/timeout" | ||
|
@@ -17,17 +17,25 @@ import ( | |
// | ||
// Usage is: | ||
// | ||
// completed := false | ||
// go syscallWatcher(context, &completed) | ||
// <syscall> | ||
// completed = true | ||
// sysycallWatcher(logContext, func() { | ||
// err = <syscall>(args...) | ||
// }) | ||
// | ||
func syscallWatcher(context logrus.Fields, syscallCompleted *bool) { | ||
time.Sleep(timeout.SyscallWatcher) | ||
if *syscallCompleted { | ||
return | ||
|
||
func syscallWatcher(logContext logrus.Fields, syscallLambda func()) { | ||
ctx, cancel := context.WithTimeout(context.Background(), timeout.SyscallWatcher) | ||
defer cancel() | ||
go watchFunc(ctx, logContext) | ||
syscallLambda() | ||
} | ||
|
||
func watchFunc(ctx context.Context, logContext logrus.Fields) { | ||
select { | ||
case <-ctx.Done(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if ctx.Err() != context.Canceled { | ||
logrus.WithFields(logContext). | ||
WithField(logfields.Timeout, timeout.SyscallWatcher). | ||
Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. If it appears to be making no forward progress, obtain the stacks and see if there is a syscall stuck in the platform API for a significant length of time.") | ||
} | ||
} | ||
logrus.WithFields(context). | ||
WithField(logfields.Timeout, timeout.SyscallWatcher). | ||
Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. If it appears to be making no forward progress, obtain the stacks and see if there is a syscall stuck in the platform API for a significant length of time.") | ||
} |
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.
Typo "sysycall"
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.
Whoops, fixed :)