serve: a request that meets a restart in progress gets an EngineDied, not an AttributeError (#1012)
Found in the live smoke: an old request that learns its engine died while restart() has already taken the process (self.proc is None) failed in death_note() with an AttributeError, and its client got no reply at all. death_note(), alive() and _send() now read the process once and treat None as a dead engine. Test: after close() the death note is a sentence, alive() is False and a send raises EngineDied.
This commit is contained in:
1 parent
3a711ae90b
commit
b6c2e01589
2 files changed
+18
-3
No files matched your search
+5
-3
@@ -721,7 +721,8 @@ class StrataEngine:
|
||||
if "issue #29" in line:
|
||||
return ("The engine stopped itself because it had stopped making progress - a hang it caught. Its log "
|
||||
"line: " + line.strip() + " - please report it at github.com/Niko1221/Strata/issues.")
|
||||
rc = self.proc.poll()
|
||||
proc = self.proc # None while a restart has not started the next one yet
|
||||
rc = proc.poll() if proc is not None else None
|
||||
if rc is not None and rc >= 0 and self.last_err: # its own last words on stdout: they say why
|
||||
return (f"The engine exited (code {rc}) after it reported: {self.last_err} - please report it at "
|
||||
"github.com/Niko1221/Strata/issues with the log.")
|
||||
@@ -734,7 +735,8 @@ class StrataEngine:
|
||||
"smaller model (Q2_0 / IQ2_XS).")
|
||||
|
||||
def alive(self) -> bool:
|
||||
return self.proc is not None and not getattr(self, "ended", False) and self.proc.poll() is None
|
||||
proc = self.proc # read once: restart() / close() may set it to None meanwhile
|
||||
return proc is not None and not getattr(self, "ended", False) and proc.poll() is None
|
||||
|
||||
def exit_code(self):
|
||||
if self.proc is None:
|
||||
@@ -894,7 +896,7 @@ class StrataEngine:
|
||||
with self.wlock:
|
||||
self.proc.stdin.write(text + "\n")
|
||||
self.proc.stdin.flush()
|
||||
except OSError: # the pipe is gone: the engine died (not the client)
|
||||
except (OSError, AttributeError): # the pipe is gone (or a restart's close() took the process):
|
||||
raise EngineDied(f"the engine stopped unexpectedly (exit code {self.exit_code()})") from None
|
||||
|
||||
def _control(self, cancel, on_token, stop_when=None):
|
||||
|
||||
@@ -171,6 +171,19 @@ class RestartWaiters(unittest.TestCase):
|
||||
def test_killed_while_reading_with_others_arriving(self):
|
||||
self.killed_mid_read(2, 2)
|
||||
|
||||
def test_an_old_request_meets_a_restart_in_progress(self):
|
||||
"""A request that learns its engine died while restart() has already taken the process (self.proc is None):
|
||||
its death note and its sends answer with EngineDied, not AttributeError (the client got no reply at all)."""
|
||||
from serve.server import EngineDied
|
||||
self.start(2)
|
||||
self.kill()
|
||||
self.engine.close() # what restart() does first
|
||||
self.assertIsNone(self.engine.proc)
|
||||
self.assertTrue(self.engine.death_note()) # a sentence, no AttributeError
|
||||
self.assertFalse(self.engine.alive())
|
||||
with self.assertRaises(EngineDied):
|
||||
self.engine._send("STOP")
|
||||
|
||||
def test_solo_engine_is_unchanged(self):
|
||||
self.start(4, fit=0) # the engine turns batching off
|
||||
self.kill()
|
||||
|
||||
Reference in new issue
Block a user