Commit Graph
22 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 abd91da5eb WebSocket: teach the input sink about EOF, and stop losing why a read failed
Follow-up to the previous commit, from Nemoumbra's questions - which found a worse
spin than the one that fix addressed.

InputSink couldn't tell "nothing right now" from "peer is gone": Fill() treats
recv() == 0 as no data and only sets hasError_ on a real error. Block() then waits
with WaitUntilReady(), which reports a closed socket as ready immediately and
forever, so TakeExact() looped on it without ever returning. A client that
disconnects with half a frame buffered - easy to do while blasting messages - put
the server in an infinite loop inside TakeExact, never even returning to Process().
Measured 7.95 CPU-seconds over 8 seconds; 0.08 after.

So: track EOF explicitly (sticky atEnd_, exposed as AtEnd()), and have Block() give
up when nothing more can arrive.

That information was being thrown away in three more places:

* Process() only tried to fill when the sink was already empty, so a disconnect went
  unnoticed for as long as there were leftovers - and if those leftovers were a
  partial frame, the read above never completed. Always fill, and close once the
  peer is gone and we've consumed what it sent.
* ReadPending() uses TakeAtMost(), which returns 0 both for "nothing right now" and
  "nothing ever again", and then reported success having consumed nothing. Ask the
  sink which it was.
* Both TakeExact() call sites answered a failed read with POLICY_VIOLATION, blaming
  the client for a protocol error when it had simply disconnected. Check the sink
  and report ABNORMAL when that's what happened.

Also stop queueing data once our own close frame is queued. RFC 6455 5.5.1 forbids
data frames after a close, and beyond the protocol, anything appended afterwards
keeps the buffers non-empty and starves the "everything is flushed" check that ends
the connection. Observed the server pumping 167MB of log broadcasts after being
asked to close.

The repeated close-and-discard is now one helper.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DCPmm7FoQUoqrbMdhfqhQ2
2026-08-31 00:57:17 +02:00
Henrik Rydgård a7b96ce7e0 Add the error flag to OutputSink as well. 2026-08-10 10:08:13 +02:00
Henrik Rydgård 0a1821f5d8 InputSink: Add an error flag. OutputSink: Unify the error handling between unix and Windows 2026-08-10 10:04:21 +02:00
Henrik Rydgård 82a3ef31b1 InputSink: Inline AccountFill into Fill 2026-08-10 10:04:21 +02:00
Henrik Rydgård d31b475bb2 Minor fixes in Common/Net from Nemo's writeup 2026-08-09 19:03:28 +02:00
Henrik Rydgård 00126e4c6f Correct some logging categories 2026-06-13 17:12:16 +02:00
Nemoumbra 1aac66a1e4 More helpful error logs for the input sink 2026-05-12 03:31:49 +03:00
Henrik Rydgård d2c9104eff Polish and fixes to the upload form. 2025-10-27 12:20:24 +01:00
Henrik Rydgård 9abd8c21e1 Finish implementing the multipart protocol, now multi file uploads work without corruption. 2025-10-27 12:20:24 +01:00
Henrik Rydgård c3aa0f7452 Centralize socket-related includes, introduce socket_errno
This resolves some weird inconsistentes and include order problems
related to errno. Needed for the next steps.
2025-01-08 12:42:45 +01:00
Henrik Rydgård e51c58716b Fix minor code issues flagged by PVS-Studio and reported by alphrixus. 2024-10-10 14:10:30 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Herman Semenov f75d7d13a0 [Net/Web] Fixed strict reduce types to 32 bit sizes, changed to memsize 2024-05-11 19:43:13 -05:00
Henrik Rydgård a416d94e38 CHD over http wasn't actually working, disable again until it can be fixed 2023-12-29 12:19:06 +01:00
Henrik Rydgård e6bc3d83f8 Logging improvement 2023-12-29 11:44:22 +01:00
Henrik Rydgård fa466d2363 Merge pull request #13850 from unknownbrackets/warnings
Cleanup some warnings and a logger shutdown crash
2021-01-01 19:53:10 +01:00
Unknown W. Brackets 8bf93bb757 http: Ignore signals on recv() too. 2021-01-01 08:58:35 -08:00
Unknown W. Brackets c3ddb279f9 http: Cleanup excessive logging. 2021-01-01 08:55:18 -08:00
Henrik Rydgård c5d90a7e50 Merge pull request #13831 from unknownbrackets/debugger
Debugger: Tweaks to memory read/write APIs
2020-12-29 10:51:02 +01:00
Unknown W. Brackets 589d83d4da http: Prevent assert on bad websocket data. 2020-12-28 09:30:36 -08:00
Unknown W. Brackets c7becb2c75 http: Treat buffer full flush correctly.
Unix platforms may fail send with EAGAIN instead of 0 bytes.
2020-12-25 22:30:43 -08:00
Henrik Rydgård 4f43cff5ca Move fileutil, net, image loaders, ui to Common. (#13506)
* Move and rename file_util/fd_util to Common/File/FileUtil and DirListing

Let's also move net while we're at it.

Move the ZIM/PNG loaders over to Common.

Move the UI framework into Common

iOS buildfix

* Buildfix

* Buildfixes

* Apple buildfix

* This typo again..

* UWP buildfix

* Fix build of PPSSPPQt, such as it is (it's not in good condition...)

* Guess what? Another buildfix.
2020-10-04 20:48:47 +02:00