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

Bugfix: don't create an announcer if closing #153

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

HDegroote
Copy link
Contributor

The race condition triggered when server.listen() created the announcer

hyperdht/lib/server.js

Lines 111 to 116 in 75059f5

await this.dht.bind()
this.target = hash(keyPair.publicKey)
this._keyPair = keyPair
this._announcer = new Announcer(this.dht, keyPair, this.target, opts)

after server.close() started executing but before await this.dht.bind()resolved, because then this._listening is not yet true, andclose() early returns if no listener is found:

hyperdht/lib/server.js

Lines 83 to 86 in 75059f5

async _close () {
this.closed = true
if (!this._listening) return

It's a catastrophic bug when it triggers, because an endless loop floods the CPU in Announcer._background():

async _background () {
while (!this.stopped) {
It will continuously throw NODE_DESTROYED errors which are caught and ignored

@mafintosh mafintosh merged commit 6f27f47 into main Dec 8, 2023
4 checks passed
@mafintosh mafintosh deleted the bugfix-no-announcer-after-close branch December 8, 2023 08:24
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