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.
This commit is contained in:
Maximilian Paß
2023-10-12 15:53:19 +02:00
parent e4769ee1b3
commit 2713e8672c

View File

@ -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
}