{"record":{"id":"4d4168d7a6d3f9c4","repo":"oraios/serena","slug":"process-terminated-while-trying-to-read-response","errorCode":null,"errorMessage":"Process terminated while trying to read response (read {len(data)} of {num_bytes} bytes before termination)","messagePattern":"Process terminated while trying to read response \\(read (.+?) of (.+?) bytes before termination\\)","errorType":"exception","errorClass":"LanguageServerTerminatedException","httpStatus":null,"severity":"critical","filePath":"src/solidlsp/ls_process.py","lineNumber":580,"sourceCode":"            self._process = None\n\n    @staticmethod\n    def _safely_close_pipe(pipe: IO[AnyStr] | None) -> None:\n        \"\"\"Safely close a pipe, ignoring any exceptions.\"\"\"\n        if pipe and not pipe.closed:\n            try:\n                pipe.close()\n            except Exception:\n                pass\n\n    def _read_bytes_from_process(self, process: ManagedSubprocess[bytes], stream: IO[bytes], num_bytes: int) -> bytes:\n        \"\"\"Read exactly num_bytes from process stdout\"\"\"\n        data = b\"\"\n        while len(data) < num_bytes:\n            chunk = stream.read(num_bytes - len(data))\n            if not chunk:\n                if process.poll() is not None:\n                    raise LanguageServerTerminatedException(\n                        f\"Process terminated while trying to read response (read {len(data)} of {num_bytes} bytes before termination)\",\n                        ls_id=self.ls_id,\n                    )\n                # Process still running but no data available yet, retry after a short delay\n                time.sleep(0.01)\n                continue\n            data += chunk\n        return data\n\n    def _read_ls_process_stdout(self) -> None:\n        \"\"\"\n        Continuously read from the language server process stdout and handle the messages\n        invoking the registered response and notification handlers\n        \"\"\"\n        exception: Exception | None = None\n        try:\n            while self._process and self._process.stdout:\n                if self._process.poll() is not None:  # process has terminated","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/ls_process.py#L562-L598","documentation":"LanguageServerTerminatedException raised in _read_bytes_from_process (src/solidlsp/ls_process.py:580) when the process's stdout ends before the expected number of bytes of an LSP message could be read. It means the language server died mid-response.","triggerScenarios":"A pending request (e.g. request_document_symbols, request_definition) whose response never arrives because the server process crashed or was killed while reading the message header/body.","commonSituations":"Server out-of-memory on very large files; server segfault on unsupported constructs; OOM-killer or timeout killing the subprocess; server crashing during bulk indexing.","solutions":["Check the language server's stderr output for the crash reason (look at logs around the failure).","Restart the language server session and retry the request.","Reduce workload size (open smaller files, limit indexed paths) to avoid OOM crashes.","Update or switch the language server version — known crash bugs are common."],"exampleFix":"// before\nsymbols = ls.request_document_symbols(large_file)\n// after\ntry:\n    symbols = ls.request_document_symbols(large_file)\nexcept LanguageServerTerminatedException:\n    ls = start_fresh_server()\n    symbols = ls.request_document_symbols(large_file)","handlingStrategy":"retry","validationCode":"def server_alive(ls) -> bool:\n    return ls.process is not None and ls.process.poll() is None","typeGuard":"def is_ls_terminated(exc: BaseException) -> bool:\n    return isinstance(exc, LanguageServerTerminatedException)","tryCatchPattern":"try:\n    result = ls.request_definition(path, line, col)\nexcept LanguageServerTerminatedException:\n    ls.restart()\n    result = ls.request_definition(path, line, col)","preventionTips":["Monitor the subprocess health and restart on death","Avoid opening extremely large files that OOM the server","Keep server versions updated to avoid known crash bugs","Wrap long batch jobs with periodic health checks"],"tags":["lsp","crash","process-terminated"],"backgroundTag":"language-server-crashed","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}