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 CHANGED
@@ -711,7 +711,7 @@ class Hypercore extends EventEmitter {
711
711
 
712
712
  async recover() {
713
713
  if (this.opened === false) await this.opening
714
- return this.state.waitForRecovery()
714
+ return this.state.waitForRecovery(this, false)
715
715
  }
716
716
 
717
717
  async setUserData(key, value) {
@@ -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 (!this.closing) {
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
- if (this.closing || !validateRecoveryPeers(peers, this.length)) {
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) await this.waitForRecovery()
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) await this.waitForRecovery()
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()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.39.0",
3
+ "version": "11.39.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {