mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 07:09:57 -04:00
Stop sending a request again to a new translator child after the first one gave no answer for the read timeout.
plat_child_read returned -1 both for a broken pipe and for a child that sent nothing for PLAT_CHILD_READ_MS (120 s), and svc_request retried any failure once on a fresh child. The translator is deterministic, so a program it hangs on hangs the second child too: a compute shader, which the replay thread looks up synchronously (vk_exec_draw.c shader_for), held the game for about 4 minutes instead of 2. plat_child_read now returns -2 on the timeout (win32.c and linux.c), child_exchange_raw returns 1, 0 for a broken pipe or a child that could not start, and -1 for the timeout, and svc_request stops the child and gives -1 without asking again; a dead child is still restarted once. translate_one fails such a request with its own reason, keeps its job and code for diagnosis and deletes whatever the stopped child wrote. The carry pass's child runs at idle priority, so a busy machine can starve it that long: carry_exchange does not resend after a timeout either, and carry_translate counts it as a failed input, not as an unavailable translator, so one slow program does not count towards the three that stop the pass. platform.h lets a build set PLAT_CHILD_READ_MS. Not reproduced before the change (no translator hang appears in the available logs). tests/child_timeout_check.py (new) builds the real child and request functions with a 300 ms timeout: a silent child gives -2 and costs one timeout with one child started, an exiting child is restarted once, an answering child gives its line. Every runtime file compiles, with no new warnings in gfx_shader.c and win32.c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2594,13 +2594,14 @@ void plat_child_lower(PlatChild *c) { // a higher nice value needs no privileg
|
||||
// A child that died makes the write fail with EPIPE; SIGPIPE is ignored for the process (main.c), as Windows has none.
|
||||
int plat_child_write(PlatChild *c, const void *data, size_t n) { return write_all(c->in, data, n); }
|
||||
|
||||
// See win32.c plat_child_read: a child that never answers fails the read after PLAT_CHILD_READ_MS.
|
||||
// See win32.c plat_child_read: a child that never answers fails the read with -2 after PLAT_CHILD_READ_MS.
|
||||
long plat_child_read(PlatChild *c, void *buf, size_t cap) {
|
||||
struct pollfd pf = {.fd = c->out, .events = POLLIN};
|
||||
int r;
|
||||
do r = poll(&pf, 1, PLAT_CHILD_READ_MS);
|
||||
while (r < 0 && errno == EINTR);
|
||||
if (r <= 0) return -1; // timed out or failed
|
||||
if (!r) return -2; // timed out
|
||||
if (r < 0) return -1; // failed
|
||||
ssize_t k;
|
||||
do k = read(c->out, buf, cap);
|
||||
while (k < 0 && errno == EINTR);
|
||||
|
||||
@@ -563,8 +563,12 @@ void plat_child_stop(PlatChild *c); // kills the child and
|
||||
// that must not slow the game down (gfx_shader.c, the carry pass).
|
||||
void plat_child_lower(PlatChild *c);
|
||||
int plat_child_write(PlatChild *c, const void *data, size_t n); // 1 when all n bytes were written
|
||||
#ifndef PLAT_CHILD_READ_MS // a check may build the child functions with a shorter one
|
||||
#define PLAT_CHILD_READ_MS 120000 // plat_child_read gives up on a child that sends nothing for this long
|
||||
long plat_child_read(PlatChild *c, void *buf, size_t cap); // bytes read (at least 1); 0 or negative: pipe broke or timed out
|
||||
#endif
|
||||
// Bytes read (at least 1); 0 or -1 when the pipe broke (the child is gone); -2 when nothing came for PLAT_CHILD_READ_MS
|
||||
// while the child kept its end open (a child stuck on its input: asking it again would wait as long).
|
||||
long plat_child_read(PlatChild *c, void *buf, size_t cap);
|
||||
|
||||
// ---- local IPC: a stream connection to another program of this machine, one listen location per name (Discord's
|
||||
// Rich Presence, discord_rpc.c). On Windows the named pipe \\.\pipe\<name>; on Linux the Unix domain socket
|
||||
|
||||
@@ -2384,15 +2384,16 @@ int plat_child_write(PlatChild *c, const void *data, size_t n) {
|
||||
}
|
||||
|
||||
// A child that stays alive but never answers (a translator stuck on one program) used to block the reader for good,
|
||||
// and with it the draw or dispatch waiting for that shader: after PLAT_CHILD_READ_MS without a byte the read fails,
|
||||
// and the caller stops the child (gfx_shader.c svc_request). The pipe is anonymous, so readiness is polled.
|
||||
// and with it the draw or dispatch waiting for that shader: after PLAT_CHILD_READ_MS without a byte the read fails
|
||||
// with -2, apart from the -1 of a broken pipe, and the caller stops the child without sending the request again
|
||||
// (gfx_shader.c svc_request). The pipe is anonymous, so readiness is polled.
|
||||
long plat_child_read(PlatChild *c, void *buf, size_t cap) {
|
||||
ULONGLONG t0 = GetTickCount64();
|
||||
for (unsigned spins = 0;; spins++) {
|
||||
DWORD avail = 0;
|
||||
if (!PeekNamedPipe(c->out, NULL, 0, NULL, &avail, NULL)) return -1; // broken: the child exited
|
||||
if (avail) break;
|
||||
if (GetTickCount64() - t0 > PLAT_CHILD_READ_MS) return -1;
|
||||
if (GetTickCount64() - t0 > PLAT_CHILD_READ_MS) return -2;
|
||||
Sleep(spins < 50 ? 0 : 1);
|
||||
}
|
||||
DWORD got = 0;
|
||||
|
||||
Reference in New Issue
Block a user