Skip to content

Fix nonblocking response write handling and backpressure #71

Description

@AlexJuca

Context

FKVS uses nonblocking sockets and buffers outgoing responses in client_t.wbuf, but the event loops currently watch read readiness only. If send() returns EAGAIN or only writes part of a response, bytes can remain in wbuf without any write-readiness registration to flush them later.

Relevant code:

  • src/commands/common/command_registry.c (wbuf_append, wbuf_flush, direct send() fallback)
  • src/networking/networking.c (try_process_frames flushes once after reads)
  • src/io/event_dispatcher_epoll.c
  • src/io/event_dispatcher_kqueue.c
  • src/io/event_dispatcher_io_uring.c

Scope

  • Track pending response bytes per client.
  • Register write readiness (EPOLLOUT/EVFILT_WRITE or io_uring send operations) when wbuf_used > 0.
  • Disable write readiness once the buffer is fully flushed.
  • Remove or make safe the direct send() fallback in wbuf_append; all writes must handle partial sends.
  • Decide how to handle clients that stay backpressured too long.

Acceptance criteria

  • Large responses and pipelined command bursts do not stall under receiver backpressure.
  • Partial writes are retried without response corruption or reordering.
  • Tests cover forced partial writes / EAGAIN behavior.
  • No unchecked send() path remains for framed responses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions