Skip to content

Remove unnecessary try/catch guards in NODERAWSOCKETS backend#27351

Open
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:unncessary-catch-guards
Open

Remove unnecessary try/catch guards in NODERAWSOCKETS backend#27351
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:unncessary-catch-guards

Conversation

@guybedford

Copy link
Copy Markdown
Collaborator

This trims the try/catch guards in the -sNODERAWSOCKETS backend down to those that are actually needed on Node 18+.

Most of the removed guards wrapped public net.Socket / net.Server stream methods (pause/resume/destroy/end/setNoDelay/setKeepAlive, server close, dgram disconnect) that never throw in the states they are called. The remaining catches all serve a real purpose: translating a Node throw into a POSIX errno, guarding a private (process.binding) or capability API, or handling a dgram double-close.

While here, out-of-range UDP setsockopt values (e.g. IP_MULTICAST_TTL=300) now return EINVAL instead of being silently swallowed. Both the public dgram path (throws) and the udp_wrap fallback path (negative libuv code) are handled, and a rejected value is dropped so it neither takes effect nor re-fails a later option replay.

test_udp_sockopts.c is extended: an out-of-range set now asserts EINVAL and a subsequent valid set still succeeds.

Made with AI assistance, under my review.

The node raw sockets backend wrapped many public net.Socket/net.Server
stream methods (pause/resume/destroy/end/setNoDelay/setKeepAlive, server
close, dgram disconnect) in try/catch even though none of them throw in the
states they are called on Node 18+. Drop those guards, keeping only the
catches that translate a genuine Node throw into a POSIX errno or guard a
private/capability API.

Also fix out-of-range UDP setsockopt values (e.g. IP_MULTICAST_TTL=300) to
return EINVAL instead of being silently swallowed, handling both the public
dgram (throws) and udp_wrap (negative libuv code) paths, and dropping the
rejected value so it neither takes effect nor re-fails a later replay.

Collapse the redundant v4/v6 multicast option keys: IP_MULTICAST_TTL and
IPV6_MULTICAST_HOPS (and likewise the two *_MULTICAST_LOOP options) map to the
same family-agnostic libuv setter, so they share one cached value each.
Comment thread src/lib/libsockfs_node.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants