hypercore 11.39.0 → 11.39.1
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 +1 -1
- package/lib/session-state.js +11 -6
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/session-state.js
CHANGED
|
@@ -612,11 +612,11 @@ class SessionState {
|
|
|
612
612
|
}
|
|
613
613
|
|
|
614
614
|
// simple tool to wait for other peers to catch us up
|
|
615
|
-
async waitForRecovery() {
|
|
615
|
+
async waitForRecovery(session, writable) {
|
|
616
616
|
const length = this.length
|
|
617
617
|
const replicator = this.core.replicator
|
|
618
618
|
|
|
619
|
-
while (
|
|
619
|
+
while (session === null ? this.core.closing === null : session.closing === null) {
|
|
620
620
|
let peers = getRecoveryPeers(replicator.peers)
|
|
621
621
|
|
|
622
622
|
if (peers.length < 1) {
|
|
@@ -631,7 +631,8 @@ class SessionState {
|
|
|
631
631
|
|
|
632
632
|
peers = getRecoveryPeers(replicator.peers)
|
|
633
633
|
|
|
634
|
-
|
|
634
|
+
const closing = session === null ? this.core.closing !== null : session.closing !== null
|
|
635
|
+
if (closing || !validateRecoveryPeers(peers, this.length)) {
|
|
635
636
|
restart = true
|
|
636
637
|
break
|
|
637
638
|
}
|
|
@@ -639,7 +640,7 @@ class SessionState {
|
|
|
639
640
|
|
|
640
641
|
if (restart) continue
|
|
641
642
|
|
|
642
|
-
if (this.length !== length) {
|
|
643
|
+
if (this.length !== length && writable) {
|
|
643
644
|
throw SESSION_NOT_WRITABLE('core recovered during append')
|
|
644
645
|
}
|
|
645
646
|
|
|
@@ -661,7 +662,9 @@ class SessionState {
|
|
|
661
662
|
async append(values, { signature, keyPair, preappend, postappend, maxLength = -1 } = {}) {
|
|
662
663
|
if (!keyPair && this.isDefault()) keyPair = this.core.header.keyPair
|
|
663
664
|
|
|
664
|
-
if (this.isDefault() && this.core.header.hints.recovering)
|
|
665
|
+
if (this.isDefault() && this.core.header.hints.recovering) {
|
|
666
|
+
await this.waitForRecovery(null, true)
|
|
667
|
+
}
|
|
665
668
|
|
|
666
669
|
await this.mutex.lock()
|
|
667
670
|
|
|
@@ -1050,7 +1053,9 @@ class SessionState {
|
|
|
1050
1053
|
throw ASSERTION('Cannot commit while repair mode is on')
|
|
1051
1054
|
}
|
|
1052
1055
|
|
|
1053
|
-
if (this.core.header.hints.recovering)
|
|
1056
|
+
if (this.core.header.hints.recovering) {
|
|
1057
|
+
await this.waitForRecovery(null, true)
|
|
1058
|
+
}
|
|
1054
1059
|
|
|
1055
1060
|
let srcLocked = false
|
|
1056
1061
|
await this.mutex.lock()
|