From 03c07738dd08fd1456f5af461b5392fafc412899 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 18:18:59 +0000 Subject: [PATCH 1/2] Initial plan From 56b03bc19e18496949283df11b1c6a497c5653b4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 18:34:03 +0000 Subject: [PATCH 2/2] fix(socket): handle partial socket_write() for large WebSocket payloads When writing large payloads on non-blocking sockets, socket_write() may write fewer bytes than requested or return false with EAGAIN when the send buffer is full. The previous code ignored the return value, causing truncated WebSocket frames and the browser error 'Could not decode a text frame as UTF-8'. Fix by adding a retry loop in writeQueue() that: - tracks how many bytes were written - suspends the fiber (via Fiber::suspend()) when EAGAIN/EWOULDBLOCK is returned, allowing the event loop to drain the buffer - retries writing the remaining bytes until all data is sent Agent-Logs-Url: https://github.com/buggregator/trap/sessions/bc577053-ad40-435d-b1ad-1a8a1f92f65b Co-authored-by: roxblnfk <4152481+roxblnfk@users.noreply.github.com> --- src/Socket/Client.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Socket/Client.php b/src/Socket/Client.php index 87a6ec1..a41ed3e 100644 --- a/src/Socket/Client.php +++ b/src/Socket/Client.php @@ -161,8 +161,23 @@ protected function processPayload(string $payload): void private function writeQueue(): void { foreach ($this->writeQueue as $data) { - \socket_write($this->socket, $data); - // Logger::debug('Respond %d bytes', $x); + $length = \strlen($data); + $written = 0; + while ($written < $length) { + $result = \socket_write($this->socket, \substr($data, $written)); + if ($result === false) { + $errno = \socket_last_error($this->socket); + // If the send buffer is temporarily full, suspend the fiber and retry + if ($errno === \SOCKET_EAGAIN || $errno === \SOCKET_EWOULDBLOCK) { + \socket_clear_error($this->socket); + \Fiber::suspend(); + continue; + } + // Unrecoverable error, stop writing + break 2; + } + $written += $result; + } } \socket_set_nonblock($this->socket);