hypercore 11.27.7 → 11.27.8

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
@@ -376,12 +376,16 @@ class Hypercore extends EventEmitter {
376
376
  const state = this.state
377
377
 
378
378
  if (opts.atom) {
379
+ await parentState.mutex.lock()
379
380
  this.state = await parentState.createSession(null, false, opts.atom)
381
+ parentState.mutex.unlock()
380
382
  if (state) state.unref()
381
383
  } else if (opts.name) {
382
384
  // todo: need to make named sessions safe before ready
383
385
  // atm we always copy the state in passCapabilities
386
+ await parentState.mutex.lock()
384
387
  this.state = await parentState.createSession(opts.name, !!opts.overwrite, null)
388
+ parentState.mutex.unlock()
385
389
  if (state) state.unref() // ref'ed above in setup session
386
390
  }
387
391
 
package/lib/core.js CHANGED
@@ -44,7 +44,6 @@ module.exports = class Core {
44
44
  this.bitfield = null
45
45
  this.verifier = null
46
46
  this.truncating = 0
47
- this.updating = false
48
47
  this.skipBitfield = null
49
48
  this.globalCache = opts.globalCache || null
50
49
  this.autoClose = opts.autoClose !== false
@@ -123,7 +123,7 @@ class SessionState {
123
123
  return this.core.header.tree.fork
124
124
  }
125
125
 
126
- async updateSnapshotStorage(storage) {
126
+ async _updateSnapshotStorage(storage) {
127
127
  if (!this.atomized || !this.atomized.flushing) return this.treeInfo()
128
128
  await this.atomized.flushed()
129
129
 
@@ -206,12 +206,16 @@ class SessionState {
206
206
  }
207
207
 
208
208
  async snapshot() {
209
- const storage = this.storage.snapshot()
210
- const treeInfo = await this.updateSnapshotStorage(storage)
209
+ try {
210
+ this.mutex.lock()
211
211
 
212
- const s = new SessionState(this.core, null, storage, treeInfo, this.name)
212
+ const storage = this.storage.snapshot()
213
+ const treeInfo = await this._updateSnapshotStorage(storage)
213
214
 
214
- return s
215
+ return new SessionState(this.core, null, storage, treeInfo, this.name)
216
+ } finally {
217
+ this._unlock()
218
+ }
215
219
  }
216
220
 
217
221
  updateDependency(tx, length) {
@@ -251,10 +255,6 @@ class SessionState {
251
255
  return true
252
256
  }
253
257
 
254
- _precommit() {
255
- this.commiting = true
256
- }
257
-
258
258
  async _commit() {
259
259
  await this.mutex.lock()
260
260
 
@@ -264,7 +264,6 @@ class SessionState {
264
264
  this.lastTruncation = null
265
265
  await this.parent._oncommit(this, bitfield)
266
266
  } finally {
267
- this.commiting = false
268
267
  this.mutex.unlock()
269
268
  }
270
269
  }
@@ -311,8 +310,7 @@ class SessionState {
311
310
 
312
311
  if (this.core.hintsChanged && this.isDefault()) await this.core.flushHints()
313
312
  } finally {
314
- this.mutex.unlock()
315
- this.core.checkIfIdle()
313
+ this._unlock()
316
314
  }
317
315
  }
318
316
 
@@ -346,7 +344,6 @@ class SessionState {
346
344
  }
347
345
 
348
346
  const tx = this.createWriteBatch()
349
- this.updating = true
350
347
 
351
348
  if (bitfield) {
352
349
  tx.putBlock(bitfield.start, value)
@@ -384,9 +381,7 @@ class SessionState {
384
381
 
385
382
  if (this.core.hintsChanged && this.isDefault()) await this.core.flushHints()
386
383
  } finally {
387
- this._clearActiveBatch()
388
- this.updating = false
389
- this.mutex.unlock()
384
+ this._unlock()
390
385
  }
391
386
 
392
387
  return true
@@ -849,7 +844,7 @@ class SessionState {
849
844
 
850
845
  if (this.core.hintsChanged && this.isDefault()) await this.core.flushHints()
851
846
  } finally {
852
- this.mutex.unlock()
847
+ this._unlock()
853
848
  }
854
849
  }
855
850
 
@@ -1027,15 +1022,8 @@ class SessionState {
1027
1022
  byteLength: this.byteLength
1028
1023
  }
1029
1024
  } finally {
1030
- this.updating = false
1031
- this.mutex.unlock()
1032
-
1033
- if (srcLocked) {
1034
- state.mutex.unlock()
1035
- state._clearActiveBatch()
1036
- }
1037
-
1038
- this.core.checkIfIdle()
1025
+ if (srcLocked) state._unlock()
1026
+ this._unlock()
1039
1027
  }
1040
1028
  }
1041
1029
 
@@ -1144,7 +1132,7 @@ class SessionState {
1144
1132
 
1145
1133
  this._moveToCore(core.core, truncated, appended)
1146
1134
  } finally {
1147
- this.mutex.unlock()
1135
+ this._unlock()
1148
1136
  }
1149
1137
  }
1150
1138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.27.7",
3
+ "version": "11.27.8",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {