Skip to content

ubusd: avoid client_cb stalls after short reads#23

Open
richard-chyu wants to merge 1 commit into
openwrt:masterfrom
richard-chyu:fix-ubusd-client-cb-short-read-stall
Open

ubusd: avoid client_cb stalls after short reads#23
richard-chyu wants to merge 1 commit into
openwrt:masterfrom
richard-chyu:fix-ubusd-client-cb-short-read-stall

Conversation

@richard-chyu

Copy link
Copy Markdown

This fixes a rare receive stall in ubusd client_cb().

client sockets are registered with ULOOP_EDGE_TRIGGER. A short positive recvmsg()/read() can leave unread data in the socket buffer, but the current code returns to the event loop and assumes another readable event will arrive. With edge-triggered polling, that is not guaranteed if no additional data arrives to create another readiness edge.

Retry the receive path immediately after making progress on an incomplete header/body read. Also treat recvmsg() == 0 as no progress/EOF to avoid retrying on a closed connection.

client_cb() uses edge-triggered uloop events for client sockets. If a
recvmsg() or read() returns fewer bytes than requested, there may still
be data buffered on the socket, but no further read event is guaranteed.

After making progress on an incomplete header or message body, retry the
receive path immediately instead of returning to the event loop. Also
treat a zero-length recvmsg() as no progress/EOF, avoiding a retry loop
on a closed connection.

Signed-off-by: Richard Yu <richard.yu@mitrastar.com.tw>
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.

1 participant