From 589ea2fe18b45328a689f5c2ff0d69afdba25a36 Mon Sep 17 00:00:00 2001 From: ecrum19 Date: Mon, 23 Nov 2026 10:13:21 +0100 Subject: [PATCH 1/2] Restart a Comunica endpoint after a crash, and resume with the next query In the vcf-bench-3 scale run (HG005, 1M records, COTTAS) the endpoint's Node worker died during q06 (V8 fatal error during garbage collection, SIGTRAP). q06 got IncompleteRead(70 bytes read), q07 a reset connection, and q08-q13 were refused: one crash cost eight queries. 9a00466 restarts the endpoint only after a timeout. - A query that loses the endpoint (refused or reset connection, or a response cut short) fails with exit 1 and is not retried; the endpoint is restarted before the next query, as after a timeout. A query the endpoint answers with an error still does not restart it. - The server log is appended to across restarts, with a "=== endpoint restarted after ===" line, so the crash's stack trace is kept instead of being truncated by the new endpoint. Co-Authored-By: Claude Opus 5.5 --- docs/validation.md | 9 ++ src/validation/validation_runner.py | 82 ++++++++++++----- test/test_query_timeout_marker_unit.py | 119 ++++++++++++++++++++++++- 3 files changed, 186 insertions(+), 24 deletions(-) diff --git a/docs/validation.md b/docs/validation.md index 0bd6758..c371f3d 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -113,6 +113,15 @@ endpoint is restarted before the next query; the restart time is reported as `endpointRestartSeconds` on that query and is not counted in its `wallSeconds`. +A crash is handled the same way. When the endpoint is lost during a query (the +connection is refused, reset, or the response is cut off, as when a Node worker +dies), that query fails with exit code 1 and is not retried, and the endpoint +is restarted before the next one, so the suite resumes after the crashed query. +A query the endpoint answers with an error does not restart it. The server log +(`-server.log`) is appended to across restarts, with a +`=== endpoint restarted after ===` line, so the crash's own output is +kept. + Options for a graph that is genuinely too large: ```bash diff --git a/src/validation/validation_runner.py b/src/validation/validation_runner.py index 9df2933..8b74f62 100644 --- a/src/validation/validation_runner.py +++ b/src/validation/validation_runner.py @@ -2744,6 +2744,25 @@ def is_timeout_error(error: BaseException) -> bool: return False +def is_endpoint_lost_error(error: BaseException) -> bool: + """Whether a query failed because the endpoint went away mid-exchange. + + A refused or reset connection, or a response cut off before its declared + length (``IncompleteRead``), means the process serving the query is gone or + being replaced -- a crashed Node worker shows up exactly like that. An + ``HTTPError``, or a URLError whose reason is not a socket error, means the + endpoint answered, so the endpoint itself is still fine. + """ + import http.client + import urllib.error + + if isinstance(error, urllib.error.HTTPError): + return False + if isinstance(error, urllib.error.URLError): + return isinstance(error.reason, OSError) + return isinstance(error, (ConnectionError, http.client.IncompleteRead)) + + def _terminate_process_group(process: subprocess.Popen) -> None: """Signal a process group, escalating to SIGKILL, and reap the leader.""" for signal_number, grace in ((signal.SIGTERM, 10), (signal.SIGKILL, 5)): @@ -2820,8 +2839,9 @@ def _init_endpoint(self, options: dict[str, Any]) -> None: self.endpoint: str | None = None self.warmup_seconds: float | None = None self.command: list[str] = [] - #: Set by a query that timed out; the next query restarts the endpoint. - self.restart_pending = False + #: The query that timed out or lost the endpoint, if any; the next + #: query restarts the endpoint first. + self.restart_after: str | None = None def _endpoint_source_argument(self) -> str: """The source argv entry, in whatever form this engine's binary needs.""" @@ -2847,7 +2867,7 @@ def _require_endpoint_binary(self) -> str: ) return self.executable - def _start_endpoint(self) -> None: + def _start_endpoint(self, *, restart_after: str | None = None) -> None: if not self.executable: self._require_endpoint_binary() self.log_dir.mkdir(parents=True, exist_ok=True) @@ -2863,9 +2883,19 @@ def _start_endpoint(self) -> None: "-t", str(self.query_timeout), ] server_log = self.log_dir / f"{self.name}-server.log" + if restart_after is None: + log_handle = server_log.open("wb") + else: + # Appended, not truncated: the log of the endpoint being replaced + # holds the evidence of why (a timeout, or a crash's stack trace). + log_handle = server_log.open("ab") + log_handle.write( + f"\n=== endpoint restarted after {restart_after} ===\n".encode("utf-8") + ) + log_handle.flush() self.server = subprocess.Popen( self.command, - stdout=server_log.open("wb"), + stdout=log_handle, stderr=subprocess.STDOUT, start_new_session=True, env=node_endpoint_env(getattr(self, "node_heap_mb", None)), @@ -3000,25 +3030,28 @@ def endpoint_describe(self) -> dict[str, Any]: "command": list(self.command), } - def _restart_after_timeout(self) -> tuple[float, str | None]: - """Replace the endpoint a timed-out query left behind. + def _restart_endpoint(self) -> tuple[float, str | None]: + """Replace the endpoint a timed-out or crashed query left behind. When Comunica's timeout fires it kills the worker and its master forks a new one, which refuses connections until it has bound. Queried at once, every remaining query failed in under a millisecond with "Connection refused" -- eight of thirteen lost to one timeout. When the - client gives up first, the worker is still busy with the old query. - Either way the endpoint cannot be trusted with the next query, so it is - restarted, at the cost of one bind and warm-up, which is charged to - neither query. Done lazily, so ``--stop-after-query-timeout`` pays - nothing for it. + client gives up first, the worker is still busy with the old query. A + crashed worker (vcf-bench-3, COTTAS, q06: a V8 fatal error during + garbage collection) leaves the same refusals behind it. + In every case the endpoint cannot be trusted with the next query, so it + is restarted, at the cost of one bind and warm-up, which is charged to + neither query. The query that failed is not retried: its failure is the + result. Done lazily, so ``--stop-after-query-timeout`` pays nothing for + it. """ - self.restart_pending = False + restart_after, self.restart_after = self.restart_after, None warmup_seconds = self.warmup_seconds started = time.monotonic() self.stop() try: - self._start_endpoint() + self._start_endpoint(restart_after=restart_after) except RuntimeError as error: self.stop() return time.monotonic() - started, str(error) @@ -3028,8 +3061,8 @@ def _restart_after_timeout(self) -> tuple[float, str | None]: def execute(self, query_id: str, query_path: Path) -> dict[str, Any]: restart: dict[str, Any] = {} - if self.restart_pending: - seconds, failure = self._restart_after_timeout() + if self.restart_after is not None: + seconds, failure = self._restart_endpoint() restart["endpointRestartSeconds"] = seconds if failure is not None: restart["endpointRestartError"] = failure @@ -3060,10 +3093,19 @@ def _execute(self, query_id: str, query_path: Path) -> dict[str, Any]: # 124 is the timeout convention the query loop keys on; anything # else here really is an execution failure. timed_out = is_timeout_error(error) - self.restart_pending = timed_out - message = ( - f"query exceeded {self.query_timeout}s" if timed_out else str(error) - ) + endpoint_lost = not timed_out and is_endpoint_lost_error(error) + if timed_out or endpoint_lost: + self.restart_after = query_id + if timed_out: + message = f"query exceeded {self.query_timeout}s" + elif endpoint_lost: + message = ( + f"{self.name} endpoint was lost during the query ({error}); " + f"it is restarted before the next query. See " + f"{self.name}-server.log for the cause" + ) + else: + message = str(error) return self._envelope( query_id, query_path, returncode=124 if timed_out else 1, started=started, raw_path=raw_path, stderr_path=stderr_path, @@ -3072,7 +3114,7 @@ def _execute(self, query_id: str, query_path: Path) -> dict[str, Any]: # The truncated body is kept as the evidence of what was received. raw_path.write_bytes(payload) if ends_with_timeout_marker(payload): - self.restart_pending = True + self.restart_after = query_id message = ( f"query exceeded {self.query_timeout}s (the endpoint ended its " f"response with {COMUNICA_TIMEOUT_MARKER.decode()})" diff --git a/test/test_query_timeout_marker_unit.py b/test/test_query_timeout_marker_unit.py index d989bfb..3765179 100644 --- a/test/test_query_timeout_marker_unit.py +++ b/test/test_query_timeout_marker_unit.py @@ -12,10 +12,17 @@ any exit-0 result that is not SPARQL Results JSON fails, and the endpoint is restarted before the next query so one timeout costs one query, not the rest of the suite. + +A crash is handled the same way. In the same run the COTTAS endpoint's worker +died during q06 (a V8 fatal error during garbage collection, SIGTRAP): q06 got +``IncompleteRead(70 bytes read)``, q07 a reset connection, and q08-q13 were +refused. The crashed query is a failure; the endpoint is restarted and the +suite resumes with the next query. """ import argparse import copy +import http.client import importlib.util import json import tempfile @@ -58,17 +65,23 @@ class FakeComunica: again -- what the real master does while it forks a replacement worker. """ - def __init__(self, *, timeouts=(), answers=None, restartable=True): + def __init__(self, *, timeouts=(), crashes=(), answers=None, restartable=True): self.timeouts = set(timeouts) + self.crashes = set(crashes) self.answers = answers or {} self.restartable = restartable self.alive = False self.starts = 0 self.queries = [] + self.log = None - def popen(self, *_args, **_kwargs): + def popen(self, *_args, **kwargs): self.starts += 1 self.alive = self.starts == 1 or self.restartable + self.log = kwargs.get("stdout") + if self.log is not None: + self.log.write(f"Server running (start {self.starts})\n".encode("utf-8")) + self.log.flush() process = mock.MagicMock() process.poll.return_value = None return process @@ -77,9 +90,16 @@ def post(self, _engine, _endpoint, query, *, timeout): if not self.alive: raise urllib.error.URLError(ConnectionRefusedError(111, "Connection refused")) query_id = query.splitlines()[0].lstrip("# ").strip() - if query_id not in self.answers and query_id not in self.timeouts: + if query_id not in set(self.answers) | self.timeouts | self.crashes: return EMPTY_RESULT # bind and warm-up probes self.queries.append(query_id) + if query_id in self.crashes: + # What the real worker left: a stack trace in the log, and a + # response cut off before its declared length. + self.alive = False + self.log.write(b"# Fatal error in , line 0\nWorker 69 died with SIGTRAP.\n") + self.log.flush() + raise http.client.IncompleteRead(b"x" * 70) if query_id in self.timeouts: self.alive = False return RECORDED_TIMEOUT_BODY @@ -186,7 +206,7 @@ def post(engine, endpoint, query, *, timeout): self.assertEqual(fake.starts, 2) def test_an_ordinary_failure_does_not_restart_the_endpoint(self): - """Only a timeout leaves the worker in doubt; a refused query does not.""" + """A query the endpoint answers with a rejection leaves the endpoint fine.""" fake = FakeComunica(answers={"q06": {"results": {"bindings": []}}}) original = fake.post @@ -215,6 +235,97 @@ def test_an_endpoint_that_will_not_restart_fails_the_rest_quickly(self): self.assertIn("not running", later["error"]) self.assertNotIn("endpointRestartSeconds", later) + def test_a_crash_fails_that_query_and_the_suite_resumes_after_it(self): + """vcf-bench-3, COTTAS: one crash in q06 cost q06-q13; now it costs q06.""" + answer = {"results": {"bindings": [{"n": {"value": "1"}}]}} + fake = FakeComunica( + crashes={"q06"}, answers={q: answer for q in ("q05", "q07", "q08")} + ) + _engine, _warmup, results, _raws = self._run(fake, ["q05", "q06", "q07", "q08"]) + before, crashed, after, later = results + + self.assertEqual(before["status"], "PASS") + self.assertEqual(crashed["status"], "EXECUTION_FAILED") + # A crash is not a timeout: exit 1, so --stop-after-query-timeout + # does not treat it as one. + self.assertEqual(crashed["exitCode"], 1) + self.assertIn("endpoint was lost", crashed["error"]) + self.assertIn("IncompleteRead", crashed["error"]) + self.assertEqual(after["status"], "PASS") + self.assertEqual(later["status"], "PASS") + # The crashed query is not retried, and every later query runs. + self.assertEqual(fake.queries, ["q05", "q06", "q07", "q08"]) + self.assertEqual(fake.starts, 2) + self.assertIn("endpointRestartSeconds", after) + self.assertNotIn("endpointRestartSeconds", later) + + def test_a_refused_or_reset_connection_also_restarts_the_endpoint(self): + """What the queries after the crash saw before the restart existed.""" + answer = {"results": {"bindings": []}} + for error in ( + urllib.error.URLError(ConnectionRefusedError(111, "Connection refused")), + ConnectionResetError(104, "Connection reset by peer"), + ): + with self.subTest(error=type(error).__name__): + fake = FakeComunica(answers={"q08": answer}) + original = fake.post + + def post(engine, endpoint, query, *, timeout, error=error): + if query.startswith("# q07"): + raise error + return original(engine, endpoint, query, timeout=timeout) + + fake.post = post + _engine, _warmup, (lost, after), _raws = self._run(fake, ["q07", "q08"]) + self.assertEqual(lost["exitCode"], 1) + self.assertIn("endpoint was lost", lost["error"]) + self.assertEqual(after["status"], "PASS") + self.assertEqual(fake.starts, 2) + + def test_the_restart_keeps_the_crash_in_the_server_log(self): + """The stack trace is the only record of why the endpoint died.""" + answer = {"results": {"bindings": []}} + fake = FakeComunica(crashes={"q06"}, answers={"q07": answer}) + with tempfile.TemporaryDirectory() as td: + tmp_path = Path(td) + source = tmp_path / "cohort.nt" + source.write_bytes(b"

.\n") + engine = V.build_engine( + "comunica", source, raw_dir=tmp_path, scratch=tmp_path, + options={"query_timeout": 3600}, + ) + patches = fake.patches() + for patch in patches: + patch.start() + try: + engine.start() + for qid in ("q06", "q07"): + engine.execute(qid, query_file(tmp_path, qid)) + engine.stop() + finally: + for patch in reversed(patches): + patch.stop() + log = (engine.log_dir / "comunica-server.log").read_text(encoding="utf-8") + self.assertIn("Server running (start 1)", log) + self.assertIn("Worker 69 died with SIGTRAP", log) + self.assertIn("=== endpoint restarted after q06 ===", log) + self.assertIn("Server running (start 2)", log) + self.assertLess(log.index("SIGTRAP"), log.index("restarted after q06")) + + def test_only_a_lost_connection_counts_as_a_lost_endpoint(self): + self.assertTrue(V.is_endpoint_lost_error(http.client.IncompleteRead(b"", 10))) + self.assertTrue(V.is_endpoint_lost_error(ConnectionResetError())) + self.assertTrue(V.is_endpoint_lost_error(http.client.RemoteDisconnected())) + self.assertTrue(V.is_endpoint_lost_error( + urllib.error.URLError(ConnectionRefusedError(111, "Connection refused")) + )) + # The endpoint answered: its verdict on the query is the result. + self.assertFalse(V.is_endpoint_lost_error( + urllib.error.HTTPError("http://x", 500, "error", {}, None) + )) + self.assertFalse(V.is_endpoint_lost_error(urllib.error.URLError("query rejected"))) + self.assertFalse(V.is_endpoint_lost_error(ValueError("bad JSON"))) + def test_a_marker_mid_stream_is_still_a_timeout(self): """Comunica appends the marker to whatever it had already streamed.""" self.assertTrue(V.ends_with_timeout_marker(b'{"results":{"bindings":[{"a":1},!TIMEDOUT!\n')) From abe184d3d114d572773e18c80b6cbe3c2b3d1764 Mon Sep 17 00:00:00 2001 From: ecrum19 Date: Mon, 23 Nov 2026 10:13:58 +0100 Subject: [PATCH 2/2] Release v3.3.2 A patch to semantic validation with the Comunica-backed engines (comunica, hdt, cottas). A query that hits Comunica's own timeout is recorded as a timeout, not a pass, and a timeout or a crashed endpoint is followed by an endpoint restart, so the suite resumes with the next query instead of losing every remaining one. Nothing changes what a v3.3.1 conversion writes. The conda sha256 stays a placeholder until the tag exists. Populate it with `python3 scripts/release.py 3.3.2 --fetch-conda-sha256` after pushing v3.3.2. Co-Authored-By: Claude Opus 5.5 --- CITATION.cff | 2 +- README.md | 4 ++-- conda-recipe/README.md | 4 ++-- conda-recipe/meta.yaml | 2 +- pyproject.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index deaf5d1..864f982 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ cff-version: 1.2.0 message: "If you use VCF-RDFizer in your research, please cite it using the metadata below." title: "VCF-RDFizer" type: software -version: "3.3.1" +version: "3.3.2" doi: "10.5281/zenodo.23237635" authors: - name: "VCF-RDFizer maintainers" diff --git a/README.md b/README.md index da8c54d..d869b1c 100644 --- a/README.md +++ b/README.md @@ -1125,7 +1125,7 @@ Safe termination: If you use VCF-RDFizer in a publication, please cite: -VCF-RDFizer maintainers. (2026). *VCF-RDFizer* (Version 3.3.1) [Computer software]. GitHub. https://github.com/ecrum19/VCF-RDFizer +VCF-RDFizer maintainers. (2026). *VCF-RDFizer* (Version 3.3.2) [Computer software]. GitHub. https://github.com/ecrum19/VCF-RDFizer BibTeX: @@ -1134,7 +1134,7 @@ BibTeX: author = {{VCF-RDFizer maintainers}}, title = {VCF-RDFizer}, year = {2026}, - version = {3.3.1}, + version = {3.3.2}, url = {https://github.com/ecrum19/VCF-RDFizer}, doi = {10.5281/zenodo.23237635}, note = {Computer software} diff --git a/conda-recipe/README.md b/conda-recipe/README.md index 84d65b0..c91c6c9 100644 --- a/conda-recipe/README.md +++ b/conda-recipe/README.md @@ -7,11 +7,11 @@ do not submit this package to `staged-recipes`. ## Before submitting to conda-forge -1. Commit the version bump, then create and push a Git tag (for example `v3.3.1`). +1. Commit the version bump, then create and push a Git tag (for example `v3.3.2`). 2. Download the source tarball and compute sha256: ```bash curl -L -o vcf-rdfizer.tar.gz \ - https://github.com/ecrum19/VCF-RDFizer/archive/refs/tags/v3.3.1.tar.gz + https://github.com/ecrum19/VCF-RDFizer/archive/refs/tags/v3.3.2.tar.gz shasum -a 256 vcf-rdfizer.tar.gz ``` 3. Replace `version` and `sha256` in the feedstock's `recipe/meta.yaml`. diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 812045f..3e26392 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -1,5 +1,5 @@ {% set name = "vcf-rdfizer" %} -{% set version = "3.3.1" %} +{% set version = "3.3.2" %} package: name: {{ name|lower }} diff --git a/pyproject.toml b/pyproject.toml index 9d020bf..44f0c3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "vcf-rdfizer" -version = "3.3.1" +version = "3.3.2" description = "Docker-first VCF to RDF conversion targeting the VCF Core vocabulary, with compressed queryable representations (HDT, COTTAS), semantic validation, and data linking" readme = "README.md" requires-python = ">=3.10"