Harden TCP/UDP socket loops and use RTHS-friendly network defaults#12
Open
joecga4 wants to merge 1 commit into
Open
Harden TCP/UDP socket loops and use RTHS-friendly network defaults#12joecga4 wants to merge 1 commit into
joecga4 wants to merge 1 commit into
Conversation
Robustness (bug fixes): - The 9 recv/send loops in the vendored TCP_Socket never checked the return value: peer close (recv() == 0) spins forever and an error (-1) moves the data pointer backwards while growing the byte count (memory corruption). All loops now treat <= 0 as an error and return -1, retry on EINTR, and the send paths restore the caller's byte-swapped data before bailing out. - Same treatment for the 8 recvfrom/sendto chunk loops in UDP_Socket, which now advance by the actual byte count. - TCP_SocketSSL treats SSL_read() == 0 (clean shutdown) as an error (was only < 0). - The C client stubs chunked UDP at 512 bytes while the C++ side used 9126: a C++->C message over 512 bytes was silently truncated. Both sides now use the same value. Latency/reliability defaults (hybrid-simulation traffic is small request/response messages every integration step): - TCP_NODELAY on by default in TCP_Socket/TCP_SocketSSL and in the C client stubs (Nagle + delayed-ACK added ~40 ms stalls per step). - MAX_UDP_DATAGRAM 9126 -> 1432 so a logical datagram fits in one MTU (one lost IP fragment dropped the whole message). Socket.h, Socket.cpp and the C stubs stay in sync; both ends of a UDP channel must be rebuilt together. - UDP_Socket requests 512 KB SO_RCVBUF/SO_SNDBUF in its three constructors so per-step datagram bursts are not dropped. Measured on OneBayFrame distributed (3 processes): max DAQ round-trip 1224 -> 82 us; local and distributed outputs bit-identical to the pre-change baseline. The same fixes are proposed for OpenSees's SRC/actor/channel copies so host and vendored sockets stay consistent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Socket fixes in the vendored
SRC/openseesExtracopies and thesimApplicationClientC stubs, from profiling real-time hybrid simulation runs. The same changes are proposed for OpenSees'sSRC/actor/channeloriginals in aschellenberg74/OpenSees#6 so host and vendored sockets stay consistent.Robustness (bug fixes)
TCP_Socketnever check the return value: peer close (recv() == 0) spins forever, and on error (−1) the data pointer moves backwards while the byte count grows (memory corruption). All loops now treat<= 0as an error and return −1, retry onEINTR, and the send paths restore the caller's byte-swapped data before bailing out.recvfrom/sendtochunk loops inUDP_Socket(which now also advance by actual byte count).TCP_SocketSSLtreatedSSL_read() == 0(clean shutdown) as success; checks are now<= 0.Latency/reliability defaults
TCP_NODELAYon by default inTCP_Socket/TCP_SocketSSLand the C stubs (Nagle + delayed-ACK added ~40 ms stalls per step).MAX_UDP_DATAGRAM9126 → 1432 so a logical datagram fits in one MTU; one lost IP fragment used to drop the whole message. Both ends of a UDP channel must be rebuilt together.UDP_Socketrequests 512 KBSO_RCVBUF/SO_SNDBUFin its three constructors.Measured: OneBayFrame distributed (3 processes), max DAQ round-trip 1224 → 82 µs; local and distributed recorder outputs bit-identical to the pre-change baseline; loadPackage integration test against a host OpenSeesPy OK.
🤖 Generated with Claude Code