OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git commits / a194ba5

Guard MetadataBase methods against null _base during joinKey
During joinKey() close/reopen cycle, _base is temporarily null. Protomux writer exchange callbacks can fire during this window. Guard all public methods to return safely instead of crashing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a194ba5717ce28dc8b37eef9bd0f0ad98f982299
by plankatron <fleeky@gmail.com> · 2026-04-04T23:48:54.000Z

Changed files (1) +6 -0

lib/metadata-base.js +6 -0
……@@ -211,6 +211,7 @@ export class MetadataBase {
211211 // ── Public API: generic ─────────────────────────────────────
212212
213213 async append (op) {
214 if (!this._base) throw new Error('MetadataBase not ready')
214215 await this._base.append(op)
215216 }
216217
……@@ -225,12 +226,14 @@ export class MetadataBase {
225226 }
226227
227228 async getByKey (key) {
229 if (!this._base) return null
228230 await this._base.update()
229231 const entry = await this._base.view.get(key)
230232 return entry ? entry.value : null
231233 }
232234
233235 async list (ns) {
236 if (!this._base) return []
234237 await this._base.update()
235238 const results = []
236239 for await (const entry of this._base.view.createReadStream({
……@@ -289,6 +292,7 @@ export class MetadataBase {
289292 // ── Writer management ───────────────────────────────────────
290293
291294 async addWriter (key) {
295 if (!this._base) return
292296 const keyHex = Buffer.isBuffer(key) ? key.toString('hex') : key
293297 await this._base.append({ ns: '_addWriter', key: keyHex, indexer: true, ts: Date.now() })
294298 }
……@@ -315,6 +319,7 @@ export class MetadataBase {
315319 // ── Writer exchange (Protomux) ──────────────────────────────
316320
317321 _exchangeWriters (socket) {
322 if (!this._base) return
318323 const mux = Protomux.from(socket)
319324 if (!mux || !this._base.key) return
320325
……@@ -375,6 +380,7 @@ export class MetadataBase {
375380 // ── Lifecycle ───────────────────────────────────────────────
376381
377382 async update () {
383 if (!this._base) return
378384 await this._base.update()
379385 }
380386