diff --git a/packages/services/src/session/default.ts b/packages/services/src/session/default.ts index 05ffeb314043..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; @@ -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",