Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore new closed connection #399

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,10 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
* Registrar notifies an established connection with pubsub protocol
*/
private onPeerConnected(peerId: PeerId, connection: Connection): void {
if (!this.isStarted()) {
this.metrics?.newConnectionCount.inc({ status: connection.stat.status })
// libp2p may emit a closed connection and never issue peer:disconnect event
// see https://github.com/ChainSafe/js-libp2p-gossipsub/issues/398
if (!this.isStarted() || connection.stat.status !== 'OPEN') {
return
}

Expand Down
6 changes: 6 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ export function getMetrics(
help: 'Total count of key collisions on fastmsgid cache put'
}),

newConnectionCount: register.gauge<{ status: string }>({
name: 'gossipsub_new_connection_total',
help: 'Total new connection by status',
labelNames: ['status']
}),

topicStrToLabel: topicStrToLabel,

toTopic(topicStr: TopicStr): TopicLabel {
Expand Down