Issues with Socket and SecureSocket error handling and documentation #55978
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
library-io
P3
A lower priority bug or feature request
triaged
Issue has been triaged by sub team
type-documentation
A request to add or improve documentation
Hello,
I'm finding the fact that
Socket
andSecureSocket
are based onStream
, error-prone, and hard to work with. I've included an example below that shows two different errors.Problem Description
Inspecting the documentation for
socket.write
, it states:The documentation for
flush
states:There are several issues here:
addStream
under the hood, making it hard to know when it's safe to callflush
.flush
documentation is vague. Does it mean thatflush
might not always work depending on the OS? It's not clear.Example Code
Before running the example, uncomment Error block 1 or 2.
While the above example is somewhat contrived, it illustrates how little it takes for errors to occur seemingly unrelated to the current operation. Writing to a socket should not leak internal stream-related errors. Is
write
usingaddStream
under the hood? It's not clear since it's all external code.Additionally, nowhere is it mentioned that write can produce errors on its own.
This makes it very hard to work with. I've encountered production code crashing at
write
orflush
, seemingly out of nowhere (maybe becauseaddStream
was incomplete?), making both methods unreliable.Request
Can anything be done to improve this? Specifically:
Documentation Improvements:
addStream
is used internally by methods likewrite
andflush
.flush
behavior.API Enhancements:
Socket
andSecureSocket
APIs to handle internal state changes more gracefully, avoiding unexpected errors.write
andflush
operations.Practical Examples:
write
andflush
in various scenarios.Would rather I wouldn't have to do something like:
General info
OS
macOS Sonoma 14.5 (23F79)
Thank you for your attention.
The text was updated successfully, but these errors were encountered: