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: sync leave() function #378

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1758,9 +1758,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
}
}

this.leave(topic).catch((err) => {
this.log(err)
})
this.leave(topic)
}

/**
Expand Down Expand Up @@ -1834,7 +1832,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
/**
* Leave topic
*/
private async leave(topic: TopicStr): Promise<void> {
private leave(topic: TopicStr): void {
if (this.status.code !== GossipStatusCode.started) {
throw new Error('Gossipsub has not started')
}
Expand All @@ -1843,15 +1841,17 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
this.metrics?.onLeave(topic)

// Send PRUNE to mesh peers
this.mesh.delete(topic)
Copy link
Member

@wemeetagain wemeetagain Nov 30, 2022

Choose a reason for hiding this comment

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

this line should be kept where it was. Or at least below L1845

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, good catch!

const meshPeers = this.mesh.get(topic)
if (meshPeers) {
await Promise.all(
Promise.all(
Array.from(meshPeers).map(async (id) => {
this.log('LEAVE: Remove mesh link to %s in %s', id, topic)
return await this.sendPrune(id, topic)
})
)
this.mesh.delete(topic)
).catch((err) => {
this.log('Error sending prunes to mesh peers', err)
})
}
}

Expand Down