Skip to content

fix(noise): return immediately when reading into an empty buffer#6494

Open
modernzju wants to merge 2 commits into
libp2p:masterfrom
modernzju:master
Open

fix(noise): return immediately when reading into an empty buffer#6494
modernzju wants to merge 2 commits into
libp2p:masterfrom
modernzju:master

Conversation

@modernzju

@modernzju modernzju commented Jun 20, 2026

Copy link
Copy Markdown

Description

This updates libp2p-noise's AsyncRead implementation to return Poll::Ready(Ok(0)) immediately when poll_read is called with an empty destination buffer.

Previously, if no decrypted data was already buffered, reading into an empty buffer could still poll the underlying framed stream and return Pending. Returning immediately matches the expected AsyncRead behavior for zero-length reads and avoids unnecessary waiting.

AI Assistance Disclosure

Tools used (required — write none if no AI was used): e.g. none / Claude Code / Copilot / Cursor / ChatGPT

Attestation (required):

  • I have read every line of this diff, understand what it does, and can explain it in review.

Notes & open questions

This does not change the Noise protocol framing or any public API.
It only handles the zero-length read case before polling the underlying stream.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@jxs

jxs commented Jun 22, 2026

Copy link
Copy Markdown
Member

Hi, and thanks for this.
Looking into the code I didn't see any calls to Output::poll_read with empty buffers, making this change redundant. Can you elaborate on why do you require this and fill out the PR form please?

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.

2 participants