Skip to content

refactor: resolve the poll_read control-message FIXME by looping - #80

Draft
ArniDagur wants to merge 1 commit into
rustls:mainfrom
ArniDagur:fix-poll-read-control-message-loop
Draft

ArniDagur wants to merge 1 commit into
rustls:mainfrom
ArniDagur:fix-poll-read-control-message-loop

Conversation

@ArniDagur

@ArniDagur ArniDagur commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

After consuming a control message with a raw recvmsg, poll_read couldn't know whether the socket had more to offer, and the raw syscall registers no interest with the runtime, so it woke its own waker and returned Pending — forcing an unnecessary reschedule and extra poll for every ignored control message (such as a TLS 1.3 NewSessionTicket).

This PR restructures poll_read as a loop:

  • Extracts control-message handling into KtlsStream::handle_control_message, keeping the read_closed / write_closed / send_close_notify side effects in place and returning a two-variant ControlMessageOutcome (Continue or Eof).
  • Loops in poll_read, polling the inner IO again on ControlMessageOutcome::Continue so it either makes progress (data or another control message) or registers the waker directly.
  • Replaces the magic 5 with libc::EIO.
  • Drops the unnecessary cx.waker().wake_by_ref() on the drained-data path, which already returns Poll::Ready(Ok(())).

The control-message handling logic itself is unchanged. Best viewed with "Hide whitespace" enabled.

@ArniDagur
ArniDagur marked this pull request as draft December 3, 2026 04:16
@ArniDagur
ArniDagur force-pushed the fix-poll-read-control-message-loop branch from 51e14fe to 397c5c3 Compare December 3, 2026 04:25
After consuming a control message with a raw `recvmsg`, `poll_read`
couldn't know whether the socket had more to offer, and the raw syscall
registers no interest with the runtime, so it woke its own waker and
returned `Pending` -- forcing an unnecessary reschedule and extra poll
for every ignored control message (such as a TLS 1.3 NewSessionTicket).

Extract control-message handling into `KtlsStream::handle_control_message`
returning a two-variant `ControlMessageOutcome` (`Continue` or `Eof`), and
restructure `poll_read` as a loop that polls the inner IO again on
`Continue`. Also use `libc::EIO` instead of the magic constant `5`, and
drop the unnecessary self-wake on the drained-data path, which already
returns `Ready` immediately.

The control-message handling logic itself is unchanged.
@ArniDagur
ArniDagur force-pushed the fix-poll-read-control-message-loop branch from 397c5c3 to f873d78 Compare December 3, 2026 04:31
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