Skip to content

Commit 531dcd6

Browse files
committed
fix(vm): always stop the VM even on SSM errors
1 parent d00ebd1 commit 531dcd6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/backend/src/functions/circuit.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ const waitForVMCommandExecution = (ssm: SSMClient, vmInstanceId: string, command
271271
} catch (error: any) {
272272
printLog(`Invalid command ${commandId} execution`, LogLevel.DEBUG)
273273

274+
const ec2 = await createEC2Client()
275+
await stopEC2Instance(ec2, vmInstanceId)
276+
274277
if (!error.toString().includes(commandId)) logAndThrowError(COMMON_ERRORS.CM_INVALID_COMMAND_EXECUTION)
275278

276279
// Reject the promise.
@@ -697,8 +700,16 @@ export const verifycontribution = functionsV2.https.onCall(
697700
}
698701

699702
// Stop VM instance
700-
if (isUsingVM) await stopEC2Instance(ec2, vmInstanceId)
701-
703+
if (isUsingVM) {
704+
// using try and catch as the VM stopping function can throw
705+
// however we want to continue without stopping as the
706+
// verification was valid, and inform the coordinator
707+
try {
708+
await stopEC2Instance(ec2, vmInstanceId)
709+
} catch (error: any) {
710+
printLog(`Error while stopping VM instance ${vmInstanceId} - Error ${error}`, LogLevel.WARN)
711+
}
712+
}
702713
// Step (1.A.4.C)
703714
if (!isFinalizing) {
704715
// Step (1.A.4.C.1)

0 commit comments

Comments
 (0)