Send output files on timeout

The unconventional use of callbacks to return both an error and data
after compilation created a subtle bug where the output files were
dropped by the LockManager in case of an error such as a timeout.

This prevented the frontend to show error logs when a timeout occurs,
creating confusion among users.

We now attach the output files to the error so that they reach the
controller and are sent back to the web service.
This commit is contained in:
Eric Mc Sween 2019-10-22 15:30:14 -04:00
parent 7d3fa7a128
commit dab6e9aa8e
4 changed files with 22 additions and 17 deletions

View file

@ -26,15 +26,13 @@ module.exports = CompileController =
status = "terminated" status = "terminated"
else if error?.validate else if error?.validate
status = "validation-#{error.validate}" status = "validation-#{error.validate}"
else if error?.timedout
status = "timedout"
logger.log err: error, project_id: request.project_id, "timeout running compile"
else if error? else if error?
if error.timedout status = "error"
status = "timedout" code = 500
logger.log err: error, project_id: request.project_id, "timeout running compile" logger.warn err: error, project_id: request.project_id, "error running compile"
else
status = "error"
code = 500
logger.warn err: error, project_id: request.project_id, "error running compile"
else else
status = "failure" status = "failure"
for file in outputFiles for file in outputFiles
@ -49,6 +47,9 @@ module.exports = CompileController =
if file.path is "core" if file.path is "core"
logger.error project_id:request.project_id, req:req, outputFiles:outputFiles, "core file found in output" logger.error project_id:request.project_id, req:req, outputFiles:outputFiles, "core file found in output"
if error?
outputFiles = error.outputFiles || []
timer.done() timer.done()
res.status(code or 200).send { res.status(code or 200).send {
compile: compile:

View file

@ -106,10 +106,11 @@ module.exports = CompileManager =
error = new Error("compilation") error = new Error("compilation")
error.validate = "fail" error.validate = "fail"
# compile was killed by user, was a validation, or a compile which failed validation # compile was killed by user, was a validation, or a compile which failed validation
if error?.terminated or error?.validate if error?.terminated or error?.validate or error?.timedout
OutputFileFinder.findOutputFiles resourceList, compileDir, (err, outputFiles) -> OutputFileFinder.findOutputFiles resourceList, compileDir, (err, outputFiles) ->
return callback(err) if err? return callback(err) if err?
callback(error, outputFiles) # return output files so user can check logs error.outputFiles = outputFiles # return output files so user can check logs
callback(error)
return return
# compile completed normally # compile completed normally
return callback(error) if error? return callback(error) if error?

View file

@ -29,3 +29,6 @@ describe "Timed out compile", ->
it "should return a timedout status", -> it "should return a timedout status", ->
@body.compile.status.should.equal "timedout" @body.compile.status.should.equal "timedout"
it "should return the log output file name", ->
outputFilePaths = @body.compile.outputFiles.map((x) => x.path)
outputFilePaths.should.include('output.log')