hypercore 11.0.5 → 11.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/session-state.js +13 -5
- package/package.json +1 -1
package/lib/session-state.js
CHANGED
|
@@ -19,6 +19,10 @@ module.exports = class SessionState {
|
|
|
19
19
|
this.name = name
|
|
20
20
|
this.sessions = []
|
|
21
21
|
|
|
22
|
+
// small hack to close old storages as late as possible.
|
|
23
|
+
// TODO: add a read lock so we can avoid that
|
|
24
|
+
this.lingers = null
|
|
25
|
+
|
|
22
26
|
this.parent = parent
|
|
23
27
|
this.mutex = new Mutex()
|
|
24
28
|
|
|
@@ -135,6 +139,10 @@ module.exports = class SessionState {
|
|
|
135
139
|
this.index = -1
|
|
136
140
|
this.core.checkIfIdle()
|
|
137
141
|
|
|
142
|
+
if (this.lingers !== null) {
|
|
143
|
+
for (const storage of this.lingers) await storage.close()
|
|
144
|
+
}
|
|
145
|
+
|
|
138
146
|
return closing
|
|
139
147
|
}
|
|
140
148
|
|
|
@@ -230,6 +238,9 @@ module.exports = class SessionState {
|
|
|
230
238
|
|
|
231
239
|
// handle migration
|
|
232
240
|
if (src.core !== this.core) {
|
|
241
|
+
if (this.lingers === null) this.lingers = []
|
|
242
|
+
this.lingers.push(this.storage)
|
|
243
|
+
|
|
233
244
|
this.prologue = src.prologue
|
|
234
245
|
this.storage = await src.core.state.storage.resumeSession(this.name)
|
|
235
246
|
this.tree = new MerkleTree(this.storage)
|
|
@@ -241,8 +252,6 @@ module.exports = class SessionState {
|
|
|
241
252
|
}
|
|
242
253
|
|
|
243
254
|
this._moveToCore(src.core)
|
|
244
|
-
|
|
245
|
-
await this.storage.close()
|
|
246
255
|
}
|
|
247
256
|
|
|
248
257
|
const truncated = (bitfield && bitfield.truncated !== -1)
|
|
@@ -800,7 +809,8 @@ module.exports = class SessionState {
|
|
|
800
809
|
const treeLength = this.length
|
|
801
810
|
|
|
802
811
|
if (!this.isSnapshot()) {
|
|
803
|
-
|
|
812
|
+
if (this.lingers === null) this.lingers = []
|
|
813
|
+
this.lingers.push(this.storage)
|
|
804
814
|
|
|
805
815
|
const truncation = length < this.length ? await truncateAndFlush(this, length) : null
|
|
806
816
|
const treeInfo = truncation ? truncation.tree : await state._getTreeHeadAt(this.length)
|
|
@@ -830,8 +840,6 @@ module.exports = class SessionState {
|
|
|
830
840
|
if (dependency) this.storage.updateDependencyLength(this.dependencyLength)
|
|
831
841
|
this.ontruncate(tree, tree.length, treeLength, flushed)
|
|
832
842
|
}
|
|
833
|
-
|
|
834
|
-
await oldStorage.close()
|
|
835
843
|
}
|
|
836
844
|
|
|
837
845
|
if (!this.storage.atom) {
|