Spaces:
Paused
Paused
icebear0828 Claude Opus 4.6 (1M context) commited on
Commit ·
1301d7a
1
Parent(s): 2996fd8
fix: server restart hanging when active SSE connections exist
Browse filesserver.close() waits for all connections to drain before calling its
callback, which hangs indefinitely with active SSE streams. Add a 3s
timeout to force shutdown, ensuring the restart handler always spawns
the new process and exits.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- src/index.ts +11 -1
src/index.ts
CHANGED
|
@@ -135,7 +135,7 @@ export async function startServer(options?: StartOptions): Promise<ServerHandle>
|
|
| 135 |
|
| 136 |
const close = (): Promise<void> => {
|
| 137 |
return new Promise((resolve) => {
|
| 138 |
-
|
| 139 |
stopUpdateChecker();
|
| 140 |
stopProxyUpdateChecker();
|
| 141 |
stopModelRefresh();
|
|
@@ -144,6 +144,16 @@ export async function startServer(options?: StartOptions): Promise<ServerHandle>
|
|
| 144 |
cookieJar.destroy();
|
| 145 |
accountPool.destroy();
|
| 146 |
resolve();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
});
|
| 148 |
});
|
| 149 |
};
|
|
|
|
| 135 |
|
| 136 |
const close = (): Promise<void> => {
|
| 137 |
return new Promise((resolve) => {
|
| 138 |
+
const cleanup = () => {
|
| 139 |
stopUpdateChecker();
|
| 140 |
stopProxyUpdateChecker();
|
| 141 |
stopModelRefresh();
|
|
|
|
| 144 |
cookieJar.destroy();
|
| 145 |
accountPool.destroy();
|
| 146 |
resolve();
|
| 147 |
+
};
|
| 148 |
+
// Force-close after 3s if active connections prevent graceful shutdown
|
| 149 |
+
const forceTimer = setTimeout(() => {
|
| 150 |
+
console.warn("[Server] Graceful close timed out (3s), forcing shutdown...");
|
| 151 |
+
cleanup();
|
| 152 |
+
}, 3000);
|
| 153 |
+
forceTimer.unref();
|
| 154 |
+
server.close(() => {
|
| 155 |
+
clearTimeout(forceTimer);
|
| 156 |
+
cleanup();
|
| 157 |
});
|
| 158 |
});
|
| 159 |
};
|