ソースを参照

refactor(subprocess): keep runner error bindings one-shot

pku-xht 1 ヶ月 前
親
コミット
5e3eaea742

+ 1 - 5
packages/subprocess/subprocess-local/src/spawn-runner.ts

@@ -46,12 +46,9 @@ interface UvErrorBindings {
   errorName(error: number): string
 }
 
-let cachedUvErrorBindings: UvErrorBindings | undefined
-
 function loadUvErrorBindings(): UvErrorBindings {
-  if (cachedUvErrorBindings !== undefined) return cachedUvErrorBindings
   const node = koffi.load(null)
-  cachedUvErrorBindings = {
+  return {
     translateSystemError: node.func(
       'uv_translate_sys_error',
       'int',
@@ -63,7 +60,6 @@ function loadUvErrorBindings(): UvErrorBindings {
       ['int'],
     ) as unknown as UvErrorBindings['errorName'],
   }
-  return cachedUvErrorBindings
 }
 
 /** Injectable operations used by the protocol-owner tests. */

+ 15 - 17
packages/subprocess/subprocess-local/tests/spawn-runner.spec.ts

@@ -651,23 +651,21 @@ describe('Windows Job runner protocol owner', () => {
   })
 
   it('loads the error translation functions from Node-linked libuv', async () => {
-    for (let attempt = 0; attempt < 2; attempt += 1) {
-      const host = new FakeRunnerHost()
-      const native = internals({
-        spawnCurrentTokenJobProcess: vi.fn(() => { throw new Win32Error('CreateProcessW', 2) }),
-      })
-      Reflect.deleteProperty(native, 'uvErrorBindings')
-      await runWindows(host, native)
-      expect(host.sent).toMatchObject([{
-        type: 'error',
-        error: {
-          code: 'ENOENT',
-          errno: process.platform === 'win32' ? -4058 : -2,
-          path: 'tool.exe',
-          spawnargs: ['literal arg'],
-        },
-      }])
-    }
+    const host = new FakeRunnerHost()
+    const native = internals({
+      spawnCurrentTokenJobProcess: vi.fn(() => { throw new Win32Error('CreateProcessW', 2) }),
+    })
+    Reflect.deleteProperty(native, 'uvErrorBindings')
+    await runWindows(host, native)
+    expect(host.sent).toMatchObject([{
+      type: 'error',
+      error: {
+        code: 'ENOENT',
+        errno: process.platform === 'win32' ? -4058 : -2,
+        path: 'tool.exe',
+        spawnargs: ['literal arg'],
+      },
+    }])
   })
 
   it.skipIf(process.platform !== 'win32')('preserves native EMFILE and UNKNOWN translations', async () => {