hypercore 11.0.5 → 11.0.7
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/core.js +2 -2
- package/lib/replicator.js +1 -1
- package/lib/session-state.js +14 -5
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -649,8 +649,8 @@ module.exports = class Core {
|
|
|
649
649
|
this.updateContiguousLength({ start, length, drop: true })
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
-
async _onconflict (proof
|
|
653
|
-
await this.replicator.onconflict(
|
|
652
|
+
async _onconflict (proof) {
|
|
653
|
+
await this.replicator.onconflict()
|
|
654
654
|
|
|
655
655
|
for (let i = this.monitors.length - 1; i >= 0; i--) {
|
|
656
656
|
const s = this.monitors[i]
|
package/lib/replicator.js
CHANGED
|
@@ -1578,7 +1578,7 @@ module.exports = class Replicator {
|
|
|
1578
1578
|
}
|
|
1579
1579
|
|
|
1580
1580
|
// Called externally when a conflict has been detected and verified
|
|
1581
|
-
async onconflict (
|
|
1581
|
+
async onconflict () {
|
|
1582
1582
|
const all = []
|
|
1583
1583
|
for (const peer of this.peers) {
|
|
1584
1584
|
all.push(peer._onconflict())
|
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
|
|
|
@@ -225,11 +233,15 @@ module.exports = class SessionState {
|
|
|
225
233
|
}
|
|
226
234
|
|
|
227
235
|
if (src.dependencyLength > this.dependencyLength) {
|
|
236
|
+
this.dependencyLength = src.dependencyLength
|
|
228
237
|
this.storage.updateDependencyLength(src.dependencyLength)
|
|
229
238
|
}
|
|
230
239
|
|
|
231
240
|
// handle migration
|
|
232
241
|
if (src.core !== this.core) {
|
|
242
|
+
if (this.lingers === null) this.lingers = []
|
|
243
|
+
this.lingers.push(this.storage)
|
|
244
|
+
|
|
233
245
|
this.prologue = src.prologue
|
|
234
246
|
this.storage = await src.core.state.storage.resumeSession(this.name)
|
|
235
247
|
this.tree = new MerkleTree(this.storage)
|
|
@@ -241,8 +253,6 @@ module.exports = class SessionState {
|
|
|
241
253
|
}
|
|
242
254
|
|
|
243
255
|
this._moveToCore(src.core)
|
|
244
|
-
|
|
245
|
-
await this.storage.close()
|
|
246
256
|
}
|
|
247
257
|
|
|
248
258
|
const truncated = (bitfield && bitfield.truncated !== -1)
|
|
@@ -800,7 +810,8 @@ module.exports = class SessionState {
|
|
|
800
810
|
const treeLength = this.length
|
|
801
811
|
|
|
802
812
|
if (!this.isSnapshot()) {
|
|
803
|
-
|
|
813
|
+
if (this.lingers === null) this.lingers = []
|
|
814
|
+
this.lingers.push(this.storage)
|
|
804
815
|
|
|
805
816
|
const truncation = length < this.length ? await truncateAndFlush(this, length) : null
|
|
806
817
|
const treeInfo = truncation ? truncation.tree : await state._getTreeHeadAt(this.length)
|
|
@@ -830,8 +841,6 @@ module.exports = class SessionState {
|
|
|
830
841
|
if (dependency) this.storage.updateDependencyLength(this.dependencyLength)
|
|
831
842
|
this.ontruncate(tree, tree.length, treeLength, flushed)
|
|
832
843
|
}
|
|
833
|
-
|
|
834
|
-
await oldStorage.close()
|
|
835
844
|
}
|
|
836
845
|
|
|
837
846
|
if (!this.storage.atom) {
|