Skip to content

Comments

chore: log message id if send queue full instead of full raw message#6263

Merged
mergify[bot] merged 4 commits intolibp2p:masterfrom
IronJam11:aaryan-issue-6252
Feb 17, 2026
Merged

chore: log message id if send queue full instead of full raw message#6263
mergify[bot] merged 4 commits intolibp2p:masterfrom
IronJam11:aaryan-issue-6252

Conversation

@IronJam11
Copy link
Contributor

Description

Fixes #6252

Reduce log size for "Send Queue full" warnings by avoiding printing large message data.

Previously, when the send queue was full, the warning log would print the entire RpcOut using its Debug implementation, which included the complete RawMessage with potentially massive byte arrays (data, signature, key fields). In high-traffic scenarios, this resulted in extremely large log files and unnecessary disk I/O.

This PR introduces a RpcLog wrapper struct with a custom Debug implementation that:

  • For Publish and Forward variants: logs only the essential debugging information (message_id, topic, source, sequence_number, validated) while omitting the large byte arrays (data, signature, key, and timeout)
  • For other variants (Subscribe, Unsubscribe, Graft, Prune, IHave, IWant, IDontWant): logs normally as they don't contain large data

This change significantly reduces log file sizes in high-load scenarios while maintaining all useful debugging information for troubleshooting.

Notes & open questions

The timeout field (a Delay type) is also omitted from the log output for Publish and Forward variants. While this field could be useful for debugging, the Delay type doesn't have a human-readable debug representation that shows the deadline, so including it wouldn't add much value to the logs.

All existing tests pass with these changes.

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

@IronJam11 IronJam11 changed the title [CHORE]: log message id if send queue full instead of full raw message chore: log message id if send queue full instead of full raw message Feb 3, 2026
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for this, but this is un-required, we can just manually impl Display for RpcOut with just the message type and message id/topic hash

@IronJam11
Copy link
Contributor Author

IronJam11 commented Feb 10, 2026

Hi, thanks for this, but this is un-required, we can just manually impl Display for RpcOut with just the message type and message id/topic hash

Makes sense, I will make the required changes

@jxs
Copy link
Member

jxs commented Feb 11, 2026

Hi have been needing this on a separate feature, this is what I'd suggest:

impl std::fmt::Display for RpcOut {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            RpcOut::Publish { message_id, .. } => write!(f, "Rpc Out Publish id: {}", message_id),
            RpcOut::Forward { message_id, .. } => write!(f, "Rpc Out Forward id: {}", message_id),
            RpcOut::Subscribe {
                topic,
                requests_partial,
                supports_partial,
            } => write!(
                f,
                "Rpc Out Subscribe topic: {}, supports_partial: {}, requests_partial: {}",
                topic, supports_partial, requests_partial
            ),
            RpcOut::Unsubscribe(topic_hash) => {
                write!(f, "Rpc Out Unsubscribe topic: {}", topic_hash)
            }
            RpcOut::Graft(graft) => write!(f, "Rpc Out Graft topic: {}", graft.topic_hash),
            RpcOut::Prune(prune) => write!(f, "Rpc Out Prune topic: {}", prune.topic_hash),
            RpcOut::IHave(ihave) => write!(
                f,
                "Rpc Out IHAVE topic: {}, message ids: {:?}",
                ihave.topic_hash, ihave.message_ids
            ),
            RpcOut::IWant(iwant) => write!(f, "Rpc Out IWANT message ids: {:?}", iwant.message_ids),
            RpcOut::IDontWant(idontwant) => write!(
                f,
                "Rpc Out IDONTWANT message ids: {:?}",
                idontwant.message_ids
            ),
            RpcOut::Extensions(extensions) => {
                write!(
                    f,
                    "Rpc Out Extensions message test_extension: {}, partial_messages: {}",
                    extensions.test_extension.unwrap_or_default(),
                    extensions.partial_messages.unwrap_or_default()
                )
            }
            RpcOut::TestExtension => todo!(),
            RpcOut::PartialMessage(partial_message) => write!(
                f,
                "Rpc Out Partial Message topic: {}, group id : {:?}",
                partial_message.topic_hash, partial_message.group_id
            ),
        }
    }
}

@IronJam11
Copy link
Contributor Author

@jxs To reduce log size and avoid printing large message data, I implemented a custom Display trait for the RpcOut enum in types.rs as directed by you. In behaviour.rs, I removed the use of the non-existent RpcLog wrapper and updated the send queue full warning to use the new Display implementation, changing the log line to print only concise RpcOut details. I also removed the RpcLog import. As a result, all relevant logs now output only minimal, relevant information, preventing large byte arrays from being written to logs, while maintaining all necessary debugging context.

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jxs To reduce log size and avoid printing large message data, I implemented a custom Display trait for the RpcOut enum in types.rs as directed by you. In behaviour.rs, I removed the use of the non-existent RpcLog wrapper and updated the send queue full warning to use the new Display implementation, changing the log line to print only concise RpcOut details. I also removed the RpcLog import. As a result, all relevant logs now output only minimal, relevant information, preventing large byte arrays from being written to logs, while maintaining all necessary debugging context.

ok sorry I was just updating the PR as we can simplify further, we can impl a custom Debug for RawMessage where we just count the bytes in the message data

impl std::fmt::Debug for RawMessage {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("RawMessage")
            .field("source", &self.source)
            .field("data length", &self.data.len())
            .field("sequence_number", &self.sequence_number)
            .field("topic", &self.topic)
            .field("signature", &self.signature)
            .field("key", &self.key)
            .field("validated", &self.validated)
            .finish()
    }
}

thanks!

@IronJam11
Copy link
Contributor Author

If I am not wrong, the debug approach needs to be implemented right (as done before)? @jxs

@jxs
Copy link
Member

jxs commented Feb 17, 2026

If I am not wrong, the debug approach needs to be implemented right (as done before)? @jxs

you just need to remove the Debug on derive and add that manual implementation after the struct declaration types.rs line 164

@IronJam11
Copy link
Contributor Author

@jxs does it look good now??

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, only two suggestions left.
Can you also add a CHANGELOG.md entry please?
thanks!

@IronJam11
Copy link
Contributor Author

done as requested @jxs

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@jxs jxs added the send-it label Feb 17, 2026
@mergify mergify bot added the queued label Feb 17, 2026
@mergify mergify bot merged commit 3591add into libp2p:master Feb 17, 2026
68 of 70 checks passed
@mergify
Copy link
Contributor

mergify bot commented Feb 17, 2026

Merge Queue Status

Rule: default


  • Entered queue2026-02-17 22:07 UTC
  • Checks passed · in-place
  • Merged2026-02-17 22:07 UTC · at edb96287b4b46b416c6191d6631cbdf113341db6

This pull request spent 5 seconds in the queue, with no time running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check rustdoc intra-doc links
    • check-neutral = Check rustdoc intra-doc links
    • check-skipped = Check rustdoc intra-doc links
  • any of [🛡 GitHub branch protection]:
    • check-success = rustfmt
    • check-neutral = rustfmt
    • check-skipped = rustfmt
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-metrics
    • check-neutral = Test libp2p-metrics
    • check-skipped = Test libp2p-metrics
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile on x86_64-apple-darwin
    • check-neutral = Compile on x86_64-apple-darwin
    • check-skipped = Compile on x86_64-apple-darwin
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile on x86_64-pc-windows-msvc
    • check-neutral = Compile on x86_64-pc-windows-msvc
    • check-skipped = Compile on x86_64-pc-windows-msvc
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-yamux
    • check-neutral = Test libp2p-yamux
    • check-skipped = Test libp2p-yamux
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-swarm
    • check-neutral = Test libp2p-swarm
    • check-skipped = Test libp2p-swarm
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-mdns
    • check-neutral = Test libp2p-mdns
    • check-skipped = Test libp2p-mdns
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-relay
    • check-neutral = Test libp2p-relay
    • check-skipped = Test libp2p-relay
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-uds
    • check-neutral = Test libp2p-uds
    • check-skipped = Test libp2p-uds
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-rendezvous
    • check-neutral = Test libp2p-rendezvous
    • check-skipped = Test libp2p-rendezvous
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p
    • check-neutral = Test libp2p
    • check-skipped = Test libp2p
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-noise
    • check-neutral = Test libp2p-noise
    • check-skipped = Test libp2p-noise
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-gossipsub
    • check-neutral = Test libp2p-gossipsub
    • check-skipped = Test libp2p-gossipsub
  • any of [🛡 GitHub branch protection]:
    • check-success = Test rw-stream-sink
    • check-neutral = Test rw-stream-sink
    • check-skipped = Test rw-stream-sink
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-dns
    • check-neutral = Test libp2p-dns
    • check-skipped = Test libp2p-dns
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-floodsub
    • check-neutral = Test libp2p-floodsub
    • check-skipped = Test libp2p-floodsub
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-swarm-derive
    • check-neutral = Test libp2p-swarm-derive
    • check-skipped = Test libp2p-swarm-derive
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-pnet
    • check-neutral = Test libp2p-pnet
    • check-skipped = Test libp2p-pnet
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-tls
    • check-neutral = Test libp2p-tls
    • check-skipped = Test libp2p-tls
  • any of [🛡 GitHub branch protection]:
    • check-success = Test multistream-select
    • check-neutral = Test multistream-select
    • check-skipped = Test multistream-select
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-kad
    • check-neutral = Test libp2p-kad
    • check-skipped = Test libp2p-kad
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-core
    • check-neutral = Test libp2p-core
    • check-skipped = Test libp2p-core
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-tcp
    • check-neutral = Test libp2p-tcp
    • check-skipped = Test libp2p-tcp
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-websocket
    • check-neutral = Test libp2p-websocket
    • check-skipped = Test libp2p-websocket
  • any of [🛡 GitHub branch protection]:
    • check-success = IPFS Integration tests
    • check-neutral = IPFS Integration tests
    • check-skipped = IPFS Integration tests
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-identify
    • check-neutral = Test libp2p-identify
    • check-skipped = Test libp2p-identify
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-dcutr
    • check-neutral = Test libp2p-dcutr
    • check-skipped = Test libp2p-dcutr
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile on wasm32-unknown-emscripten
    • check-neutral = Compile on wasm32-unknown-emscripten
    • check-skipped = Compile on wasm32-unknown-emscripten
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile with select features (mdns tcp dns tokio)
    • check-neutral = Compile with select features (mdns tcp dns tokio)
    • check-skipped = Compile with select features (mdns tcp dns tokio)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-request-response
    • check-neutral = Test libp2p-request-response
    • check-skipped = Test libp2p-request-response
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile on wasm32-unknown-unknown
    • check-neutral = Compile on wasm32-unknown-unknown
    • check-skipped = Compile on wasm32-unknown-unknown
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-mplex
    • check-neutral = Test libp2p-mplex
    • check-skipped = Test libp2p-mplex
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-ping
    • check-neutral = Test libp2p-ping
    • check-skipped = Test libp2p-ping
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-plaintext
    • check-neutral = Test libp2p-plaintext
    • check-skipped = Test libp2p-plaintext
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-autonat
    • check-neutral = Test libp2p-autonat
    • check-skipped = Test libp2p-autonat
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-quic
    • check-neutral = Test libp2p-quic
    • check-skipped = Test libp2p-quic
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-webrtc
    • check-neutral = Test libp2p-webrtc
    • check-skipped = Test libp2p-webrtc
  • any of [🛡 GitHub branch protection]:
    • check-success = Test quick-protobuf-codec
    • check-neutral = Test quick-protobuf-codec
    • check-skipped = Test quick-protobuf-codec
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-identity
    • check-neutral = Test libp2p-identity
    • check-skipped = Test libp2p-identity
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-allow-block-list
    • check-neutral = Test libp2p-allow-block-list
    • check-skipped = Test libp2p-allow-block-list
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-swarm-test
    • check-neutral = Test libp2p-swarm-test
    • check-skipped = Test libp2p-swarm-test
  • any of [🛡 GitHub branch protection]:
    • check-success = Check for changes in proto files
    • check-neutral = Check for changes in proto files
    • check-skipped = Check for changes in proto files
  • any of [🛡 GitHub branch protection]:
    • check-success = Ensure that Cargo.lock is up-to-date
    • check-neutral = Ensure that Cargo.lock is up-to-date
    • check-skipped = Ensure that Cargo.lock is up-to-date
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-connection-limits
    • check-neutral = Test libp2p-connection-limits
    • check-skipped = Test libp2p-connection-limits
  • any of [🛡 GitHub branch protection]:
    • check-success = examples
    • check-neutral = examples
    • check-skipped = examples
  • any of [🛡 GitHub branch protection]:
    • check-success = Run all WASM tests
    • check-neutral = Run all WASM tests
    • check-skipped = Run all WASM tests
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-memory-connection-limits
    • check-neutral = Test libp2p-memory-connection-limits
    • check-skipped = Test libp2p-memory-connection-limits
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-webtransport-websys
    • check-neutral = Test libp2p-webtransport-websys
    • check-skipped = Test libp2p-webtransport-websys
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-perf
    • check-neutral = Test libp2p-perf
    • check-skipped = Test libp2p-perf
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile with MSRV
    • check-neutral = Compile with MSRV
    • check-skipped = Compile with MSRV
  • any of [🛡 GitHub branch protection]:
    • check-success = manifest_lint
    • check-neutral = manifest_lint
    • check-skipped = manifest_lint
  • any of [🛡 GitHub branch protection]:
    • check-success = Test libp2p-server
    • check-neutral = Test libp2p-server
    • check-skipped = Test libp2p-server
  • any of [🛡 GitHub branch protection]:
    • check-success = Compile on wasm32-wasip1
    • check-neutral = Compile on wasm32-wasip1
    • check-skipped = Compile on wasm32-wasip1

@mergify mergify bot removed the queued label Feb 17, 2026
@IronJam11
Copy link
Contributor Author

thank you for your guidance on this @jxs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log message id if send queue full instead of full raw message

2 participants