node-opcua-pki 6.7.1 → 6.7.2

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/dist/index.mjs CHANGED
@@ -2273,22 +2273,31 @@ var CertificateManager = class _CertificateManager extends EventEmitter {
2273
2273
  ...usePolling ? { interval: pollingInterval } : {},
2274
2274
  persistent: false
2275
2275
  };
2276
- const createUnreffedWatcher = (folder) => {
2277
- const capturedHandles = [];
2278
- const origWatch = fs9.watch;
2279
- fs9.watch = ((...args) => {
2280
- const handle = origWatch.apply(fs9, args);
2281
- capturedHandles.push(handle);
2282
- return handle;
2276
+ const allCapturedHandles = [];
2277
+ const origWatch = fs9.watch;
2278
+ let watcherReadyCount = 0;
2279
+ const totalWatchers = 5;
2280
+ fs9.watch = ((...args) => {
2281
+ const handle = origWatch.apply(fs9, args);
2282
+ handle.setMaxListeners(handle.getMaxListeners() + 1);
2283
+ handle.on("error", () => {
2283
2284
  });
2285
+ allCapturedHandles.push(handle);
2286
+ return handle;
2287
+ });
2288
+ const createUnreffedWatcher = (folder) => {
2289
+ const startIdx = allCapturedHandles.length;
2284
2290
  const w = chokidar.watch(folder, chokidarOptions);
2285
2291
  const unreffAll = () => {
2286
- fs9.watch = origWatch;
2287
- for (const h of capturedHandles) {
2288
- h.unref();
2292
+ for (let i = startIdx; i < allCapturedHandles.length; i++) {
2293
+ allCapturedHandles[i].unref();
2294
+ }
2295
+ watcherReadyCount++;
2296
+ if (watcherReadyCount >= totalWatchers) {
2297
+ fs9.watch = origWatch;
2289
2298
  }
2290
2299
  };
2291
- return { w, capturedHandles, unreffAll };
2300
+ return { w, capturedHandles: allCapturedHandles.slice(startIdx), unreffAll };
2292
2301
  };
2293
2302
  await Promise.all([
2294
2303
  this.#scanCertFolder(this.trustedFolder, this.#thumbs.trusted),
@@ -2350,6 +2359,9 @@ var CertificateManager = class _CertificateManager extends EventEmitter {
2350
2359
  */
2351
2360
  #startCrlWatcher(folder, index, createUnreffedWatcher, store) {
2352
2361
  const { w, unreffAll } = createUnreffedWatcher(folder);
2362
+ w.on("error", (err) => {
2363
+ debugLog(`chokidar CRL watcher error on ${folder}:`, err);
2364
+ });
2353
2365
  let ready = false;
2354
2366
  w.on("unlink", (filename) => {
2355
2367
  for (const [key, data] of index.entries()) {
@@ -2385,6 +2397,9 @@ var CertificateManager = class _CertificateManager extends EventEmitter {
2385
2397
  */
2386
2398
  #startWatcher(folder, index, createUnreffedWatcher, store) {
2387
2399
  const { w, unreffAll } = createUnreffedWatcher(folder);
2400
+ w.on("error", (err) => {
2401
+ debugLog(`chokidar cert watcher error on ${folder}:`, err);
2402
+ });
2388
2403
  let ready = false;
2389
2404
  w.on("unlink", (filename) => {
2390
2405
  debugLog(chalk6.cyan(`unlink in folder ${folder}`), filename);