hypercore 11.0.4 → 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/index.js +2 -2
- package/lib/session-state.js +14 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -341,14 +341,14 @@ class Hypercore extends EventEmitter {
|
|
|
341
341
|
|
|
342
342
|
const parent = opts.parent || this.core
|
|
343
343
|
const checkout = opts.checkout === undefined ? -1 : opts.checkout
|
|
344
|
+
const state = this.state
|
|
344
345
|
|
|
345
346
|
if (opts.atom) {
|
|
346
347
|
this.state = await parent.state.createSession(null, checkout, false, opts.atom)
|
|
348
|
+
if (state) state.unref()
|
|
347
349
|
} else if (opts.name) {
|
|
348
350
|
// todo: need to make named sessions safe before ready
|
|
349
351
|
// atm we always copy the state in passCapabilities
|
|
350
|
-
const state = this.state
|
|
351
|
-
|
|
352
352
|
this.state = await parent.state.createSession(opts.name, checkout, !!opts.overwrite, null)
|
|
353
353
|
if (state) state.unref() // ref'ed above in setup session
|
|
354
354
|
|
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)
|
|
@@ -798,8 +809,10 @@ module.exports = class SessionState {
|
|
|
798
809
|
const treeLength = this.length
|
|
799
810
|
|
|
800
811
|
if (!this.isSnapshot()) {
|
|
801
|
-
|
|
812
|
+
if (this.lingers === null) this.lingers = []
|
|
813
|
+
this.lingers.push(this.storage)
|
|
802
814
|
|
|
815
|
+
const truncation = length < this.length ? await truncateAndFlush(this, length) : null
|
|
803
816
|
const treeInfo = truncation ? truncation.tree : await state._getTreeHeadAt(this.length)
|
|
804
817
|
|
|
805
818
|
treeInfo.fork = truncation ? this.fork + 1 : this.fork
|