From dce895faff56de11e8c59c03032e097aff3a7760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Thu, 9 Dec 2021 18:52:16 +0100 Subject: [PATCH] Move the error handler to the api querier to catch the ws normal close error for all Execute requests --- internal/nomad/api_querier.go | 6 +++++- internal/nomad/nomad.go | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/nomad/api_querier.go b/internal/nomad/api_querier.go index d818506..66b9718 100644 --- a/internal/nomad/api_querier.go +++ b/internal/nomad/api_querier.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/gorilla/websocket" nomadApi "github.com/hashicorp/nomad/api" "github.com/openHPI/poseidon/internal/config" "io" @@ -99,7 +100,10 @@ func (nc *nomadAPIClient) Execute(runnerID string, 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) - if err != nil { + if err != nil && websocket.IsCloseError(err, websocket.CloseNormalClosure) { + log.WithError(err).Info("The exit code could not be received.") + return 0, nil + } else if err != nil { return 1, fmt.Errorf("error executing command in allocation: %w", err) } return exitCode, nil diff --git a/internal/nomad/nomad.go b/internal/nomad/nomad.go index a9ed33e..096175e 100644 --- a/internal/nomad/nomad.go +++ b/internal/nomad/nomad.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/gorilla/websocket" nomadApi "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/nomad/structs" "github.com/openHPI/poseidon/internal/config" @@ -353,10 +352,7 @@ func (a *APIClient) ExecuteCommand(allocationID string, return a.executeCommandInteractivelyWithStderr(allocationID, ctx, command, stdin, stdout, stderr) } exitCode, err := a.apiQuerier.Execute(allocationID, ctx, command, tty, stdin, stdout, stderr) - if err != nil && websocket.IsCloseError(err, websocket.CloseNormalClosure) { - log.WithError(err).Info("The exit code could not be received.") - return 0, nil - } else if err != nil { + if err != nil { return 1, fmt.Errorf("error executing command in API: %w", err) } return exitCode, nil