nteract / nteract

📘 The interactive computing suite for you! ✨

Home Page:https://nteract.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi-client kernel support

shibbas opened this issue · comments

Happy to make this contribute this change to nteract! Please let me know if there is any feedback on the proposed solution below.

Application or Package Used
nteract on jupyter. And nteract packages.

Describe the bug
When you open the same notebook in two browser sessions, the websocket connection of the second session stomps on the websocket connection of the first terminating the cell execution subscriptions.

To Reproduce
Create a notebook with the following code:

import time;

for i in range(100):
    print(i)
    time.sleep(1)

Start execution and open the same notebook in another browser. Execution shows [*] in the first browser, but output stops updating.

Expected behavior
The first notebook execution should continue and the second notebook execution if started gets queued up. This seems to be Jupyter behavior.

Proposed solution
The disconnects are happening because the server session ID is being used when generating a websocket URL. It looks like nteract only supports single client sessions per notebook instance.

Jupyter messaging protocol supports client session ids. From the docs:

A client session id, in message headers from a client, should be unique among all clients connected to a kernel. When a client reconnects to a kernel, it should use the same client session id in its message headers. When a client restarts, it should generate a new client session id.

This client session id is also used as the sessionId when creating the websocket to differentiate the connection between multiple clients in Jupyter.

Using kernelRef as the client sessionID and storing both the client sessionId as well as the server session ID (since it's used for session API) can enable the multi-client support.