From 2713e8672c5f2c13c1d57aa14305d0ad41395192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:53:19 +0200 Subject: [PATCH] Add error for empty list file system execution. Normally, the result of executing the `lsCommand` should never be empty. However, we have observed that CodeOcean sometimes receives an empty JSON result if the runner is being deleted while the list file system request is processed. Therefore, we add a check if something has been written to CodeOcean and otherwise report an error. --- internal/runner/nomad_runner.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/runner/nomad_runner.go b/internal/runner/nomad_runner.go index bb4c1bc..1d13124 100644 --- a/internal/runner/nomad_runner.go +++ b/internal/runner/nomad_runner.go @@ -163,13 +163,20 @@ func (r *NomadJob) ListFileSystem( exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution, &nullio.Reader{Ctx: ctx}, ls2json, io.Discard) switch { + case ls2json.HasStartedWriting() && err == nil && exitCode == 0: + // Successful. Nothing to do. case ls2json.HasStartedWriting(): + // if HasStartedWriting the status code of the response is already sent. + // Therefore, we cannot notify CodeOcean about an error at this point anymore. + log.WithError(err).WithField("exitCode", exitCode).Warn("Ignoring error of listing the file system") err = nil case err != nil: err = fmt.Errorf("%w: nomad error during retrieve file headers: %v", nomad.ErrorExecutorCommunicationFailed, err) case exitCode != 0: err = ErrFileNotFound + case !ls2json.HasStartedWriting(): + err = fmt.Errorf("list file system failed silently: %w", nomad.ErrorExecutorCommunicationFailed) } return err }