Fix Nonblocking writes#14
Merged
Merged
Conversation
Comment on lines
+75
to
+82
| // Buffer fully drained — clear it and remove EPOLLOUT | ||
| buf.clear(); | ||
| offset = 0; | ||
|
|
||
| struct epoll_event ev; | ||
| ev.data.ptr = element; | ||
| ev.events = EPOLLIN | EPOLLET | EPOLLONESHOT; | ||
| epoll_ctl(epoll_fd, EPOLL_CTL_MOD, element->fd, &ev); |
Contributor
There was a problem hiding this comment.
May be interesting to do some form of garbage collection at some point if the buffer is too big, but for now should be fine.
TheoHollender
approved these changes
Jun 9, 2026
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.
Add non-blocking write buffer to NetQueue
Problem:
write_n_bytesspun withusleep(200)on EAGAIN. Since this runs inside dispatch handlers insidewait_and_process, send buffer pressure on any single connection stalled the entire event loop. Dropping on EAGAIN wasn't an option — losingCONNECT_TO_SWITCHorAGENT_CONNECTION_TOKENbreaks the handshake.Fix: Each
NetworkElementgets an outbound write buffer. On EAGAIN mid-write, remaining bytes are saved into the buffer andEPOLLOUTis registered on the fd. When the kernel send buffer drains, epoll fires andflush_write_bufferdrains the queue. Once empty,EPOLLOUTis deregistered. Connections exceeding 64KB buffered are markedSCK_ERRORand closed on the next loop iteration — a connection that full isn't reading.All in-loop sends in conductor, switch, and agent go through
queue->sendandqueue->send_heartbeat. Blocking MIP phase sends stay onsend_protobuf_packetsince those fds aren't in the queue yet and are still in blocking mode.