Skip to content

Commit a578c14

Browse files
committed
fix bug starting jupyter on compute server
compute server jupyter kernels relied on a subtle behavior of the cursors table.
1 parent 9ee3732 commit a578c14

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

src/packages/frontend/compute/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ComputeServersManager extends EventEmitter {
5353

5454
getComputeServers = () => {
5555
const servers = {};
56-
const cursors = this.sync_db.get_cursors().toJS();
56+
const cursors = this.sync_db.get_cursors({ excludeSelf: 'never' }).toJS();
5757
for (const client_id in cursors) {
5858
const server = cursors[client_id];
5959
servers[decodeUUIDtoNum(client_id)] = {

src/packages/frontend/frame-editors/code-editor/actions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,11 @@ export class Actions<
11501150
let cursors: Map<string, List<Map<string, any>>> = Map();
11511151
this._syncstring
11521152
.get_cursors({
1153-
excludeSelf: !redux
1153+
excludeSelf: redux
11541154
.getStore("account")
1155-
.getIn(["editor_settings", "show_my_other_cursors"]),
1155+
.getIn(["editor_settings", "show_my_other_cursors"])
1156+
? "heuristic"
1157+
: "always",
11561158
})
11571159
.forEach((info, account_id) => {
11581160
info.get("locs").forEach((loc) => {
@@ -1198,7 +1200,7 @@ export class Actions<
11981200
}
11991201
const omit_lines: SetMap = {};
12001202
const cursors = this._syncstring.get_cursors?.({
1201-
excludeSelf: false,
1203+
excludeSelf: "never",
12021204
maxAge: 3 * 60 * 1000,
12031205
}); // there are situations where get_cursors isn't defined (seen this).
12041206
if (cursors) {

src/packages/frontend/frame-editors/jupyter-editor/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ export class JupyterEditorActions extends BaseActions<JupyterEditorState> {
562562

563563
gotoUser(account_id: string, frameId?: string) {
564564
const cursors = this.jupyter_actions.syncdb
565-
.get_cursors({ maxAge: 0 })
565+
.get_cursors({ maxAge: 0, excludeSelf: "never" })
566566
?.toJS();
567567
if (cursors == null) return; // no info
568568
const locs = cursors[account_id]?.locs;

src/packages/frontend/frame-editors/whiteboard-editor/actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,9 @@ export class Actions<T extends State = State> extends BaseActions<T | State> {
10231023
}
10241024

10251025
gotoUser(account_id: string, frameId?: string) {
1026-
const cursors = this._syncstring.get_cursors({ maxAge: 0 })?.toJS();
1026+
const cursors = this._syncstring
1027+
.get_cursors({ maxAge: 0, excludeSelf: "never" })
1028+
?.toJS();
10271029
if (cursors == null) return; // no info
10281030
const locs = cursors[account_id]?.locs;
10291031
for (const loc of locs) {

src/packages/frontend/jupyter/browser-actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,11 @@ export class JupyterActions extends JupyterActions0 {
326326
) {
327327
return;
328328
}
329-
const excludeSelf = !this.redux
329+
const excludeSelf = this.redux
330330
.getStore("account")
331-
.getIn(["editor_settings", "show_my_other_cursors"]);
331+
.getIn(["editor_settings", "show_my_other_cursors"])
332+
? "heuristic"
333+
: "always";
332334
const cursors = this.syncdb.get_cursors({ excludeSelf });
333335
const cells = this.cursor_manager.process(this.store.get("cells"), cursors);
334336
if (cells != null) {

src/packages/frontend/syncdoc.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class SynchronizedDocument2 extends SynchronizedDocument
447447
delete_trailing_whitespace: =>
448448
cm = @focused_codemirror()
449449
omit_lines = {}
450-
@_syncstring.get_cursors()?.map (x, _) =>
450+
@_syncstring.get_cursors(excludeSelf:'never')?.map (x, _) =>
451451
x.get('locs')?.map (loc) =>
452452
y = loc.get('y')
453453
if y?

src/packages/sync/editor/generic/sync-doc.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export class SyncDoc extends EventEmitter {
530530
maxAge: COMPUTE_THRESH_MS,
531531
// don't exclude self since getComputeServerId called from the compute
532532
// server also to know if it is the chosen one.
533-
excludeSelf: false,
533+
excludeSelf: "never",
534534
});
535535
const dbg = this.dbg("getComputeServerId");
536536
dbg("num cursors = ", cursors.size);
@@ -549,6 +549,7 @@ export class SyncDoc extends EventEmitter {
549549
}
550550
}
551551
}
552+
552553
return isFinite(minId) ? minId : 0;
553554
};
554555

@@ -1884,13 +1885,21 @@ export class SyncDoc extends EventEmitter {
18841885

18851886
/* Returns *immutable* Map from account_id to list
18861887
of cursor positions, if cursors are enabled.
1888+
1889+
- excludeSelf: do not include our own cursor
1890+
- maxAge: only include cursors that have been updated with maxAge ms from now.
18871891
*/
1888-
public get_cursors = ({
1892+
get_cursors = ({
18891893
maxAge = 60 * 1000,
1890-
excludeSelf = true,
1894+
// excludeSelf:
1895+
// 'always' -- *always* exclude self
1896+
// 'never' -- never exclude self
1897+
// 'heuristic' -- exclude self is older than last set from here, e.g., useful on
1898+
// frontend so we don't see our own cursor unless more than one browser.
1899+
excludeSelf = "always",
18911900
}: {
18921901
maxAge?: number;
1893-
excludeSelf?: boolean;
1902+
excludeSelf?: "always" | "never" | "heuristic";
18941903
} = {}): Map<string, any> => {
18951904
this.assert_not_closed("get_cursors");
18961905
if (!this.cursors) {
@@ -1901,12 +1910,15 @@ export class SyncDoc extends EventEmitter {
19011910
}
19021911
const account_id: string = this.client_id();
19031912
let map = this.cursor_map;
1904-
if (
1905-
(excludeSelf && map.has(account_id)) ||
1906-
this.cursor_last_time >=
1907-
(map.getIn([account_id, "time"], new Date(0)) as Date)
1908-
) {
1909-
map = map.delete(account_id);
1913+
if (map.has(account_id) && excludeSelf != "never") {
1914+
if (
1915+
excludeSelf == "always" ||
1916+
(excludeSelf == "heuristic" &&
1917+
this.cursor_last_time >=
1918+
(map.getIn([account_id, "time"], new Date(0)) as Date))
1919+
) {
1920+
map = map.delete(account_id);
1921+
}
19101922
}
19111923
// Remove any old cursors, where "old" is by default more than maxAge old.
19121924
const now = Date.now();
@@ -1939,7 +1951,7 @@ export class SyncDoc extends EventEmitter {
19391951
/* Set settings map. Used for custom configuration just for
19401952
this one file, e.g., overloading the spell checker language.
19411953
*/
1942-
public set_settings = async (obj): Promise<void> => {
1954+
set_settings = async (obj): Promise<void> => {
19431955
this.assert_is_ready("set_settings");
19441956
await this.set_syncstring_table({
19451957
settings: obj,

0 commit comments

Comments
 (0)