Skip to content

Commit 09c9206

Browse files
Fix liveshare guest hang issue (#7764) (#7772)
* initial changes * update notebooks on server session change and add test * await correctly
1 parent fbc7bef commit 09c9206

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

news/2 Fixes/7638.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a hang in the Interactive window when connecting guest to host after the host has already started the interactive window.

src/client/datascience/jupyter/jupyterServer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export class JupyterServerBase implements INotebookServer {
169169
return this.notebooks.get(resource.toString());
170170
}
171171

172+
protected getNotebooks(): INotebook[] {
173+
return [...this.notebooks.values()];
174+
}
175+
172176
protected setNotebook(resource: Uri, notebook: INotebook) {
173177
const oldDispose = notebook.dispose;
174178
notebook.dispose = () => {

src/client/datascience/jupyter/liveshare/guestJupyterServer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ export class GuestJupyterServer
7373
return result;
7474
}
7575

76+
public async onSessionChange(api: vsls.LiveShare | null): Promise<void> {
77+
await super.onSessionChange(api);
78+
79+
this.notebooks.forEach(async notebook => {
80+
const guestNotebook = notebook as GuestJupyterNotebook;
81+
if (guestNotebook) {
82+
await guestNotebook.onSessionChange(api);
83+
}
84+
});
85+
}
86+
7687
public async getNotebook(resource: Uri): Promise<INotebook | undefined> {
7788
return this.notebooks.get(resource.toString());
7889
}

src/client/datascience/jupyter/liveshare/hostJupyterServer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ export class HostJupyterServer
9696
}
9797
}
9898

99+
public async onSessionChange(api: vsls.LiveShare | null): Promise<void> {
100+
await super.onSessionChange(api);
101+
102+
this.getNotebooks().forEach(async notebook => {
103+
const hostNotebook = notebook as HostJupyterNotebook;
104+
if (hostNotebook) {
105+
await hostNotebook.onSessionChange(api);
106+
}
107+
});
108+
}
109+
99110
public async onDetach(api: vsls.LiveShare | null): Promise<void> {
100111
await super.onDetach(api);
101112

src/test/datascience/liveshare.functional.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,23 @@ suite('DataScience LiveShare tests', () => {
202202
verifyHtmlOnCell(guestContainer.wrapper!, 'InteractiveCell', '<span>1</span>', CellPosition.Last);
203203
});
204204

205+
test('Host starts LiveShare after starting Jupyter', async() => {
206+
addMockData(hostContainer!, 'a=1\na', 1);
207+
addMockData(hostContainer!, 'b=2\nb', 2);
208+
await getOrCreateInteractiveWindow(vsls.Role.Host);
209+
let wrapper = await addCodeToRole(vsls.Role.Host, 'a=1\na');
210+
verifyHtmlOnCell(wrapper, 'InteractiveCell', '<span>1</span>', CellPosition.Last);
211+
212+
await startSession(vsls.Role.Host);
213+
await getOrCreateInteractiveWindow(vsls.Role.Guest);
214+
await startSession(vsls.Role.Guest);
215+
216+
wrapper = await addCodeToRole(vsls.Role.Host, 'b=2\nb');
217+
218+
assert.ok(guestContainer.wrapper, 'Guest wrapper not created');
219+
verifyHtmlOnCell(guestContainer.wrapper!, 'InteractiveCell', '<span>2</span>', CellPosition.Last);
220+
});
221+
205222
test('Host Shutdown and Run', async () => {
206223
// Should only need mock data in host
207224
addMockData(hostContainer!, 'a=1\na', 1);

0 commit comments

Comments
 (0)