{"record":{"id":"b85f902c1b8930d9","repo":"python/cpython","slug":"write-eof-already-called","errorCode":null,"errorMessage":"write_eof() already called","messagePattern":"write_eof\\(\\) already called","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/proactor_events.py","lineNumber":341,"sourceCode":"                self._read_fut.add_done_callback(self._loop_reading)\n        finally:\n            if length > -1:\n                self._data_received(data, length)\n\n\nclass _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport,\n                                      transports.WriteTransport):\n    \"\"\"Transport for write pipes.\"\"\"\n\n    _start_tls_compatible = True\n\n    def write(self, data):\n        if not isinstance(data, (bytes, bytearray, memoryview)):\n            raise TypeError(\n                f\"data argument must be a bytes-like object, \"\n                f\"not {type(data).__name__}\")\n        if self._eof_written:\n            raise RuntimeError('write_eof() already called')\n        if self._empty_waiter is not None:\n            raise RuntimeError('unable to write; sendfile is in progress')\n\n        if not data:\n            return\n\n        if self._conn_lost:\n            if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:\n                logger.warning('socket.send() raised exception.')\n            self._conn_lost += 1\n            return\n\n        # Observable states:\n        # 1. IDLE: _write_fut and _buffer both None\n        # 2. WRITING: _write_fut set; _buffer None\n        # 3. BACKED UP: _write_fut set; _buffer a bytearray\n        # We always copy the data, so the caller can't modify it\n        # while we're still waiting for the I/O to happen.","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/proactor_events.py#L323-L359","documentation":"Error \"write_eof() already called\" thrown in python/cpython.","triggerScenarios":"Raised when write_eof() is called a second time on a proactor transport.","commonSituations":"See trigger scenarios.","solutions":["Call write_eof() only once per transport; track state and skip the second call.","Check transport.is_closing() / can_write_eof() before calling write_eof()."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}