From 18c5c36f7e22f777e5b031e1594e397aa2fbb446 Mon Sep 17 00:00:00 2001 From: Sigmar Stefansson Date: Wed, 9 Oct 2024 11:51:26 +0000 Subject: [PATCH 1/2] added pseudo kernel handling in updateSession --- packages/services/src/session/default.ts | 15 ++++++--- packages/services/src/session/restapi.ts | 41 ++++++++++++++++++++---- pyproject.toml | 2 +- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/packages/services/src/session/default.ts b/packages/services/src/session/default.ts index 05ffeb314043..1b6dafaafc29 100644 --- a/packages/services/src/session/default.ts +++ b/packages/services/src/session/default.ts @@ -391,10 +391,16 @@ export class SessionConnection implements Session.ISessionConnection { private async _patch( body: DeepPartial ): Promise { - const model = await updateSession( - { ...body, id: this._id }, - this.serverSettings - ); + this._updating = true; + let model: Session.IModel; + try { + model = await updateSession( + {...body, id: this._id}, + this.serverSettings + ); + } finally { + this._updating = false; + } this.update(model); return model; } @@ -422,6 +428,7 @@ export class SessionConnection implements Session.ISessionConnection { private _clientId: string; private _kernel: Kernel.IKernelConnection | null = null; private _isDisposed = false; + private _updating = false; private _disposed = new Signal(this); private _kernelChanged = new Signal< this, diff --git a/packages/services/src/session/restapi.ts b/packages/services/src/session/restapi.ts index def827e48047..499a63d60789 100644 --- a/packages/services/src/session/restapi.ts +++ b/packages/services/src/session/restapi.ts @@ -160,16 +160,45 @@ export async function updateSession( settings: ServerConnection.ISettings = ServerConnection.makeSettings() ): Promise { const url = getSessionUrl(settings.baseUrl, model.id); - const init = { + const body = JSON.stringify(model); + const bodyjson = JSON.parse(body); + bodyjson['id'] = ''; + let init = { method: 'PATCH', body: JSON.stringify(model) }; - const response = await ServerConnection.makeRequest(url, init, settings); - if (response.status !== 200) { - const err = await ServerConnection.ResponseError.create(response); - throw err; + let data = { id: '', execution_state: 'waiting' }; + let count = 0; + while (count++ < 300) { + const response = await ServerConnection.makeRequest(url, init, settings); + if (response.status !== 200 && response.status !== 201) { + throw await ServerConnection.ResponseError.create(response); + } + data = await response.json(); + if (data.execution_state != 'waiting') { + console.log( + 'Kernel started in update session ' + data.id + ' after ' + count + ' seconds' + ); + break; + } else { + bodyjson['id'] = data.id; + init = { + method: 'PATCH', + body: JSON.stringify(bodyjson) + }; + await sleep(2000); + console.log( + 'Waiting for kernel in update session ' + + data.id + + ' for ' + + 2 * count + + ' seconds' + ); + } + } + if (count >= 300) { + throw new Error('10 minute timeout waiting for updated kernel to start'); } - const data = await response.json(); updateLegacySessionModel(data); validateModel(data); return data; diff --git a/pyproject.toml b/pyproject.toml index db6f4ca0c2a4..55f23eecf96f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ dependencies = [ "ipykernel>=6.5.0", "jinja2>=3.0.3", "jupyter_core", - "jupyter_server@git+https://github.com/spotinst/jupyter_server.git@ocean-spark-jupyterserver-jlab", + "jupyter_server@git+https://github.com/spotinst/jupyter_server.git@ddf0b98", "jupyter-lsp>=2.0.0", "jupyterlab_server>=2.27.1,<3", "notebook_shim>=0.2", From 9102bdf677606ad4d076953bd24fcf28ca1df54c Mon Sep 17 00:00:00 2001 From: Sigmar Stefansson Date: Wed, 9 Oct 2024 11:55:26 +0000 Subject: [PATCH 2/2] ignore dispose session while waiting for update --- packages/services/src/session/default.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/services/src/session/default.ts b/packages/services/src/session/default.ts index 1b6dafaafc29..3ea347204950 100644 --- a/packages/services/src/session/default.ts +++ b/packages/services/src/session/default.ts @@ -209,7 +209,7 @@ export class SessionConnection implements Session.ISessionConnection { * Dispose of the resources held by the session. */ dispose(): void { - if (this.isDisposed) { + if (this._updating || this.isDisposed) { return; } this._isDisposed = true;