()
| 74 | |
| 75 | let closed = false; |
| 76 | const close = async (): Promise<void> => { |
| 77 | if (closed) return; |
| 78 | closed = true; |
| 79 | clearTimeout(timer); |
| 80 | // `server.close()` only refuses NEW connections — it does NOT |
| 81 | // terminate existing keep-alive sockets, which browsers default to |
| 82 | // and idle for minutes (Chrome ~5min). Without `closeAllConnections` |
| 83 | // the CLI process hangs after "Signed in" until the browser closes |
| 84 | // its idle socket. `respond()` also emits `Connection: close` so the |
| 85 | // browser doesn't try to keep-alive in the first place. |
| 86 | server.closeAllConnections?.(); |
| 87 | await new Promise<void>((resolve) => server.close(() => resolve())); |
| 88 | }; |
| 89 | |
| 90 | const timer = setTimeout(() => { |
| 91 | rejectResult(new Error(`OAuth callback timed out after ${timeoutMs}ms`)); |
no test coverage detected