Skip to content

Conversation

paschal533
Copy link
Contributor

What was wrong?

When a node publishes a message immediately after connecting to a peer, py-libp2p sometimes crashes with:

KeyError: <PeerID>

This happens in pubsub/gossipsub.py, where self.peer_protocol[peer_id] is accessed before the identify handshake has finished. The handshake is asynchronous, so peer_protocol may not yet contain the connected peer.

Issue #887

How was it fixed?

  • Guarded against missing entries in peer_protocol
  • Optionally, queue publishes until identify completes.

Summary of approach.

To-Do

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

put a cute animal picture link inside the parentheses

@seetadev
Copy link
Contributor

seetadev commented Sep 4, 2025

@paschal533 : Great, thank you for submitting the PR.

Would recommend @Winter-Soren, @lla-dane and @sumanjeet0012 to share feedback on the PR. Appreciate your efforts.

@sumanjeet0012
Copy link
Contributor

@seetadev This PR introduces only an additional check before accessing it. We can proceed with merging this PR.

@seetadev seetadev merged commit a01811a into libp2p:main Sep 21, 2025
27 of 28 checks passed
@seetadev
Copy link
Contributor

@paschal533 : Thank you Paschal for your contribution and initiative on this PR. Appreciate your efforts.

@sumanjeet0012 and @pacrob: Thank you so much for your feedback. Appreciate it.

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.

4 participants