Shut down computers on errors

Previously we would attempt to resume them, which then caused confusing
behaviour if the Lua VM was in an inconsistent state.

Closes #811
This commit is contained in:
Jonathan Coates 2021-06-06 18:32:25 +01:00
parent aa9d3c8269
commit 29cc5bb86b
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 24 additions and 1 deletions

View File

@ -251,6 +251,20 @@ void queueStop( boolean reboot, boolean close )
* and then schedule a shutdown.
*/
void abort()
{
immediateFail( StateCommand.ABORT );
}
/**
* Abort this whole computer due to an internal error. This will immediately destroy the Lua machine,
* and then schedule a shutdown.
*/
void fastFail()
{
immediateFail( StateCommand.ERROR );
}
private void immediateFail( StateCommand command )
{
ILuaMachine machine = this.machine;
if( machine != null ) machine.close();
@ -258,7 +272,7 @@ void abort()
synchronized( queueLock )
{
if( closed ) return;
command = StateCommand.ABORT;
this.command = command;
if( isOn ) enqueue();
}
}
@ -596,6 +610,12 @@ void work() throws InterruptedException
displayFailure( "Error running computer", TimeoutState.ABORT_MESSAGE );
shutdown();
break;
case ERROR:
if( !isOn ) return;
displayFailure( "Error running computer", "An internal error occurred, see logs." );
shutdown();
break;
}
}
else if( event != null )
@ -644,6 +664,7 @@ private enum StateCommand
SHUTDOWN,
REBOOT,
ABORT,
ERROR,
}
private static final class Event

View File

@ -506,6 +506,8 @@ public void run()
catch( Exception | LinkageError | VirtualMachineError e )
{
ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e );
// Tear down the computer immediately. There's no guarantee it's well behaved from now on.
executor.fastFail();
}
finally
{