Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0e5f6fd

Browse files
committedJun 4, 2020
fix: providers leaking resources on dht construction
1 parent 57a0411 commit 0e5f6fd

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"delay": "^4.3.0",
7878
"dirty-chai": "^2.0.1",
7979
"it-pair": "^1.0.0",
80-
"libp2p": "libp2p/js-libp2p#0.28.x",
80+
"libp2p": "^0.28.0-rc.0",
8181
"lodash": "^4.17.11",
8282
"lodash.random": "^3.2.0",
8383
"lodash.range": "^3.2.0",

‎src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class KadDHT extends EventEmitter {
185185
*/
186186
async start () {
187187
this._running = true
188+
this.providers.start()
188189
this._queryManager.start()
189190
await this.network.start()
190191

‎src/providers.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ class Providers {
5858
this.syncQueue = new Queue({ concurrency: 1 })
5959
}
6060

61+
/**
62+
* Start the provider cleanup service
63+
*/
64+
start () {
65+
if (this._cleaner) {
66+
clearInterval(this._cleaner)
67+
}
68+
69+
this._cleaner = setInterval(
70+
() => this._cleanup(),
71+
this.cleanupInterval
72+
)
73+
}
74+
6175
/**
6276
* Release any resources.
6377
*
@@ -155,23 +169,6 @@ class Providers {
155169
return provs
156170
}
157171

158-
get cleanupInterval () {
159-
return this._cleanupInterval
160-
}
161-
162-
set cleanupInterval (val) {
163-
this._cleanupInterval = val
164-
165-
if (this._cleaner) {
166-
clearInterval(this._cleaner)
167-
}
168-
169-
this._cleaner = setInterval(
170-
() => this._cleanup(),
171-
this.cleanupInterval
172-
)
173-
}
174-
175172
/**
176173
* Add a new provider for the given CID.
177174
*

‎test/providers.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ describe('Providers', () => {
8888
providers.cleanupInterval = 100
8989
providers.provideValidity = 200
9090

91+
providers.start()
92+
9193
const cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
9294
await Promise.all([
9395
providers.addProvider(cid, peerIds[0]),
@@ -104,6 +106,7 @@ describe('Providers', () => {
104106

105107
const provsAfter = await providers.getProviders(cid)
106108
expect(provsAfter).to.have.length(0)
109+
providers.stop()
107110
})
108111

109112
// slooow so only run when you need to

0 commit comments

Comments
 (0)
This repository has been archived.