Skip to content

Commit

Permalink
pkg/vminfo: gracefully handle context abortion
Browse files Browse the repository at this point in the history
On context abortion, return a special error.
On the pkg/rpcserver side, recognize and process it.
  • Loading branch information
a-nogikh committed Feb 3, 2025
1 parent 52e7ad4 commit 8f276ef
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/fuzzer/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ func (r *Request) Done(res *Result) {
close(r.done)
}

var errContextAborted = errors.New("context closed while waiting the result")
var ErrRequestAborted = errors.New("context closed while waiting the result")

// Wait() blocks until we have the result.
func (r *Request) Wait(ctx context.Context) *Result {
r.initChannel()
select {
case <-ctx.Done():
return &Result{Status: ExecFailure, Err: errContextAborted}
return &Result{Status: ExecFailure, Err: ErrRequestAborted}
case <-r.done:
return r.result
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ func (serv *server) runCheck(ctx context.Context, info *handshakeResult) error {
close(serv.cfg.machineCheckStarted)
}
enabledCalls, disabledCalls, features, checkErr := serv.checker.Run(ctx, info.Files, info.Features)
if checkErr == vminfo.ErrAborted {
return nil
}

enabledCalls, transitivelyDisabled := serv.target.TransitivelyEnabledCalls(enabledCalls)
// Note: need to print disbled syscalls before failing due to an error.
// This helps to debug "all system calls are disabled".
Expand Down
5 changes: 4 additions & 1 deletion pkg/vminfo/syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ func (ctx *checkContext) do(fileInfos []*flatrpc.FileInfo, featureInfos []*flatr
globs := make(map[string][]string)
for _, req := range globReqs {
res := req.Wait(ctx.ctx)
if res.Status != queue.Success {
if res.Err == queue.ErrRequestAborted {
// Don't return an error on context cancellation.
return nil, nil, nil, nil
} else if res.Status != queue.Success {
return nil, nil, nil, fmt.Errorf("failed to execute glob: %w (%v)\n%s\n%s",
res.Err, res.Status, req.GlobPattern, res.Output)
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/vminfo/vminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,16 @@ func (checker *Checker) MachineInfo(fileInfos []*flatrpc.FileInfo) ([]*KernelMod
return modules, info.Bytes(), nil
}

var ErrAborted = errors.New("aborted through the context")

func (checker *Checker) Run(ctx context.Context, files []*flatrpc.FileInfo, featureInfos []*flatrpc.FeatureInfo) (
map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) {
cc := newCheckContext(ctx, checker.cfg, checker.checker, checker.executor)
return cc.do(files, featureInfos)
enabled, disabled, features, err := cc.do(files, featureInfos)
if ctx.Err() != nil {
return nil, nil, nil, ErrAborted
}
return enabled, disabled, features, err
}

// Implementation of the queue.Source interface.
Expand Down

0 comments on commit 8f276ef

Please sign in to comment.