Catch context canceled error
This commit is contained in:

committed by
Sebastian Serth

parent
160df3d9e6
commit
28fb0ca61c
@ -133,6 +133,7 @@ func (r *RunnerController) updateFileSystem(writer http.ResponseWriter, request
|
|||||||
|
|
||||||
func (r *RunnerController) fileContent(writer http.ResponseWriter, request *http.Request) {
|
func (r *RunnerController) fileContent(writer http.ResponseWriter, request *http.Request) {
|
||||||
targetRunner, _ := runner.FromContext(request.Context())
|
targetRunner, _ := runner.FromContext(request.Context())
|
||||||
|
monitoring.AddRunnerMonitoringData(request, targetRunner.ID(), targetRunner.Environment())
|
||||||
path := request.URL.Query().Get(PathKey)
|
path := request.URL.Query().Get(PathKey)
|
||||||
privilegedExecution, err := strconv.ParseBool(request.URL.Query().Get(PrivilegedExecutionKey))
|
privilegedExecution, err := strconv.ParseBool(request.URL.Query().Get(PrivilegedExecutionKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,16 +100,18 @@ func (nc *nomadAPIClient) Execute(runnerID string,
|
|||||||
return 1, fmt.Errorf("error retrieving allocation info: %w", err)
|
return 1, fmt.Errorf("error retrieving allocation info: %w", err)
|
||||||
}
|
}
|
||||||
exitCode, err := nc.client.Allocations().Exec(ctx, allocation, TaskName, tty, command, stdin, stdout, stderr, nil, nil)
|
exitCode, err := nc.client.Allocations().Exec(ctx, allocation, TaskName, tty, command, stdin, stdout, stderr, nil, nil)
|
||||||
if err != nil {
|
switch {
|
||||||
rootCause := errors.Unwrap(err)
|
case err == nil:
|
||||||
if rootCause != nil && websocket.IsCloseError(rootCause, websocket.CloseNormalClosure) {
|
return exitCode, nil
|
||||||
log.WithError(err).Info("The exit code could not be received.")
|
case websocket.IsCloseError(errors.Unwrap(err), websocket.CloseNormalClosure):
|
||||||
return 0, nil
|
log.WithField("runnerID", runnerID).WithError(err).Info("The exit code could not be received.")
|
||||||
} else {
|
return 0, nil
|
||||||
return 1, fmt.Errorf("error executing command in allocation: %w", err)
|
case errors.Is(err, context.Canceled):
|
||||||
}
|
log.WithField("runnerID", runnerID).Infof("Execution canceled by context")
|
||||||
|
return 0, nil
|
||||||
|
default:
|
||||||
|
return 1, fmt.Errorf("error executing command in allocation: %w", err)
|
||||||
}
|
}
|
||||||
return exitCode, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nc *nomadAPIClient) listJobs(prefix string) ([]*nomadApi.JobListStub, error) {
|
func (nc *nomadAPIClient) listJobs(prefix string) ([]*nomadApi.JobListStub, error) {
|
||||||
|
Reference in New Issue
Block a user