GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(browser): drop late connections of closed sessions (#11600) · vitest-dev/vitest@f161e6d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • browser/src/node
      • rpc.ts
    • vitest/src/node
      • browser
        • sessions.ts
      • pools
        • browser.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/browser/src/node/rpc.ts‎

Copy file name to clipboardExpand all lines: packages/browser/src/node/rpc.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ export function setupBrowserRpc(
109109
const sessions = vitest._browserSessions
110110

111111
if (!sessions.sessionIds.has(sessionId)) {
112+
if (sessions.closedSessionIds.has(sessionId)) {
113+
debug?.('[%s] ignoring the %s connection of a closed session', sessionId, type)
114+
socket.destroy()
115+
return
116+
}
112117
const ids = [...sessions.sessionIds].join(', ')
113118
return error(new Error(`[vitest] Unknown session id "${sessionId}". Expected one of ${ids}.`))
114119
}
Collapse file

‎packages/vitest/src/node/browser/sessions.ts‎

Copy file name to clipboardExpand all lines: packages/vitest/src/node/browser/sessions.ts
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export class BrowserSessions {
88

99
public sessionIds: Set<string> = new Set()
1010

11+
// a page can outlive the close of its session and reconnect
12+
public closedSessionIds: Set<string> = new Set()
13+
1114
getSession(sessionId: string): BrowserServerStateSession | undefined {
1215
return this.sessions.get(sessionId)
1316
}
@@ -16,6 +19,12 @@ export class BrowserSessions {
1619
this.sessions.delete(sessionId)
1720
}
1821

22+
close(sessionId: string): void {
23+
this.sessions.delete(sessionId)
24+
this.sessionIds.delete(sessionId)
25+
this.closedSessionIds.add(sessionId)
26+
}
27+
1928
createSession(
2029
sessionId: string,
2130
project: TestProject,
Collapse file

‎packages/vitest/src/node/pools/browser.ts‎

Copy file name to clipboardExpand all lines: packages/vitest/src/node/pools/browser.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ export function createBrowserPool(vitest: Vitest): BrowserPool {
285285
await Promise.all([...stopping, ...exitPromises])
286286
// pages can be opened outside of the pool (`vitest.standalone`)
287287
await Promise.all(vitest.projects.map((project) => closeProvider(project)))
288-
vitest._browserSessions.sessionIds.clear()
288+
vitest._browserSessions.sessionIds.forEach((sessionId) => {
289+
vitest._browserSessions.close(sessionId)
290+
})
289291
vitest.projects.forEach((project) => {
290292
project.browser?.state.orchestrators.forEach((orchestrator) => {
291293
orchestrator.$close()
@@ -570,8 +572,7 @@ class BrowserWorker {
570572
this.busySessions.clear()
571573
this.readySessions.clear()
572574
await closeProvider(this.project, options)
573-
// the pages are closed now, so a late reconnect is not reported as an unknown session
574-
sessionIds.forEach((sessionId) => sessions.sessionIds.delete(sessionId))
575+
sessionIds.forEach((sessionId) => sessions.close(sessionId))
575576
orchestrators.forEach((orchestrator) => orchestrator?.$close())
576577
}
577578

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.