Trying to fix long running Auto Retopo Crash
This commit is contained in:
parent
a0400f5a4d
commit
8edcfb1746
2 changed files with 40 additions and 2 deletions
|
|
@ -112,7 +112,15 @@ def _stream_tool(run_callable, fmt: str, label: str) -> StreamingResponse:
|
|||
def generate():
|
||||
yield _sse({"type": "progress", "stage": "start", "frac": 0.0, "message": f"{label} starting…"})
|
||||
while True:
|
||||
item = events.get()
|
||||
try:
|
||||
item = events.get(timeout=15)
|
||||
except queue.Empty:
|
||||
# Long blocking stages (e.g. "Building clean topology") emit no
|
||||
# progress for minutes. Send an SSE comment heartbeat so bytes keep
|
||||
# flowing; otherwise the Node proxy's fetch body timeout (~5 min of
|
||||
# silence) aborts the stream and takes the request down with it.
|
||||
yield ": keepalive\n\n"
|
||||
continue
|
||||
if item is None:
|
||||
break
|
||||
yield _sse(item)
|
||||
|
|
|
|||
32
server.js
32
server.js
|
|
@ -101,6 +101,16 @@ import {
|
|||
const app = express();
|
||||
const PORT = Number(process.env.PORT) || 3001;
|
||||
|
||||
// Last-resort safety net: a single dropped stream or stray async error should
|
||||
// never take the whole server down (which forced a full restart before). Log
|
||||
// and keep serving; individual requests still fail on their own if broken.
|
||||
process.on('uncaughtException', err => {
|
||||
console.error('Uncaught exception (server kept alive):', err);
|
||||
});
|
||||
process.on('unhandledRejection', reason => {
|
||||
console.error('Unhandled promise rejection (server kept alive):', reason);
|
||||
});
|
||||
|
||||
// Build the externally-reachable base URL ("http://host:port") from the
|
||||
// incoming request so generated asset/media URLs point back at whatever host
|
||||
// and port the client actually used to reach us — works on another machine or
|
||||
|
|
@ -5774,7 +5784,27 @@ async function proxyMeshTool(operationPath, req, res) {
|
|||
res.end();
|
||||
return undefined;
|
||||
}
|
||||
return Readable.fromWeb(upstream.body).pipe(res);
|
||||
|
||||
// Stream the upstream SSE to the browser. An aborted/failed upstream (e.g. the
|
||||
// Python service dies, or undici's fetch body timeout fires on a long silent
|
||||
// stage) makes this Readable emit 'error'. `.pipe()` does NOT forward source
|
||||
// errors, so without this handler the unhandled 'error' would crash the whole
|
||||
// Node process — taking every other endpoint (footer /system/stats, etc.) with
|
||||
// it. Handle it: log, send a terminal SSE error so the browser stops waiting,
|
||||
// and close cleanly.
|
||||
const source = Readable.fromWeb(upstream.body);
|
||||
source.on('error', err => {
|
||||
console.error(`Mesh tool proxy (${operationPath}) upstream stream error:`, err);
|
||||
if (!res.writableEnded) {
|
||||
try {
|
||||
res.write(`data: ${JSON.stringify({ type: 'error', detail: 'The mesh service connection was lost.' })}\n\n`);
|
||||
} catch { /* response already gone */ }
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
// If the browser hangs up, stop reading the upstream.
|
||||
res.on('close', () => { if (!source.destroyed) source.destroy(); });
|
||||
return source.pipe(res);
|
||||
}
|
||||
|
||||
app.post('/api/meshes/auto-uv', meshToolsUpload.single('meshFile'), async (req, res) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue