diff --git a/packages/adapters/src/kubernetes-instance-adapter.ts b/packages/adapters/src/kubernetes-instance-adapter.ts index 7be572307..0048c447b 100644 --- a/packages/adapters/src/kubernetes-instance-adapter.ts +++ b/packages/adapters/src/kubernetes-instance-adapter.ts @@ -228,7 +228,10 @@ IComponent { this.logger.error("Trying to stop non existent runner", this._runnerName); } else { await this.timeout(ms); - await this.kubeClient.deletePod(this._runnerName, 2); + await this.kubeClient.deletePod(this._runnerName, 2) + .catch((e) => { + this.logger.error("Error deleting pod", e, this._runnerName); + }); this._runnerName = undefined; } diff --git a/packages/cli/src/lib/config/profileConfig.ts b/packages/cli/src/lib/config/profileConfig.ts index c1ade9874..40303d916 100644 --- a/packages/cli/src/lib/config/profileConfig.ts +++ b/packages/cli/src/lib/config/profileConfig.ts @@ -32,7 +32,7 @@ export default class ProfileConfig extends ConfigFileDefault { try { const stopResult = await this.instanceStopped(); + this.logger.debug("Stop result", stopResult); + if (stopResult) { - code = stopResult.exitcode; + code = stopResult.exitcode || code; this.logger.trace("Instance ended with code", code); this.status = stopResult.status; this.setExitInfo(code, stopResult.message); + + this.logger.debug("Exit info", this.terminated); } } catch (e: any) { code = e.exitcode; + this.status = e.status || InstanceStatus.ERRORED; this.setExitInfo(code, e.reason); - this.logger.error("Instance caused error", e.message, code); + this.logger.error("Instance caused error", e); } finally { clearInterval(interval); } @@ -274,7 +279,7 @@ export class CSIController extends TypedEmitter { this.emit("terminated", code); - this.logger.trace("Finalizing..."); + this.logger.trace("Finalizing...", code); await this.finalize(); @@ -299,7 +304,7 @@ export class CSIController extends TypedEmitter { const exitcode = await this.endOfSequence; - this.logger.trace("End of sequence"); + this.logger.trace("End of sequence", exitcode); if (exitcode > 0) { this.status = InstanceStatus.ERRORED; @@ -320,7 +325,10 @@ export class CSIController extends TypedEmitter { }; this.instancePromise = instanceMain() - .then((exitcode) => mapRunnerExitCode(exitcode, this.sequence)) + .then((exitcode) => { + this.logger.debug("instanceMain ExitCode", exitcode); + return mapRunnerExitCode(exitcode, this.sequence); + }) .catch((error) => { this.logger.error("Instance promise rejected", error); this.initResolver?.rej(error); @@ -373,6 +381,8 @@ export class CSIController extends TypedEmitter { } instanceStopped(): CSIController["instancePromise"] { + this.logger.debug("function InstanceStopped called"); + if (!this.instancePromise) { throw new CSIControllerError("UNATTACHED_STREAMS"); } @@ -766,6 +776,8 @@ export class CSIController extends TypedEmitter { async kill(opts = { removeImmediately: false }) { if (this.status === InstanceStatus.KILLING) { await this.instanceAdapter.remove(); + + return; } this.status = InstanceStatus.KILLING; diff --git a/packages/host/src/lib/csi-dispatcher.ts b/packages/host/src/lib/csi-dispatcher.ts index dafc5a344..4876c2fca 100644 --- a/packages/host/src/lib/csi-dispatcher.ts +++ b/packages/host/src/lib/csi-dispatcher.ts @@ -182,7 +182,9 @@ export class CSIDispatcher extends TypedEmitter { delete this.instanceStore[csiController.id]; }) - .once("terminated", (code) => { + .on("terminated", (code) => { + this.logger.debug("Terminated event received", code); + if (csiController.requires && csiController.requires !== "") { (this.serviceDiscovery.getData({ topic: new TopicId(csiController.requires), diff --git a/packages/host/src/lib/host.ts b/packages/host/src/lib/host.ts index bb6c7e7b8..16ec7ddb2 100644 --- a/packages/host/src/lib/host.ts +++ b/packages/host/src/lib/host.ts @@ -393,12 +393,14 @@ export class Host implements IComponent { * @param {DispatcherInstanceTerminatedEventData} eventData Event details. */ async handleDispatcherTerminatedEvent(eventData: DispatcherInstanceTerminatedEventData) { + this.logger.debug("handleDispatcherTerminatedEvent", eventData); + this.auditor.auditInstance(eventData.id, InstanceMessageCode.INSTANCE_TERMINATED); this.pushTelemetry("Instance terminated", { executionTime: eventData.info.executionTime.toString(), id: eventData.id, - code: eventData.code.toString(), + code: (eventData.code || -2).toString(), seqId: eventData.sequence.id }); }