@avalw/search-worker 2.3.3 → 2.3.5

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.
Files changed (2) hide show
  1. package/index.js +21 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @avalw/search-worker v2.3.2
2
+ * @avalw/search-worker v2.3.5
3
3
  * Distributed Cache Worker for AVALW Search Network
4
4
  *
5
5
  * Workers connect to the coordinator via WebSocket and serve as
@@ -425,6 +425,7 @@ class SearchWorker {
425
425
  this.reconnectTimeout = null;
426
426
  this.reconnectAttempts = 0;
427
427
  this.maxReconnectAttempts = 10;
428
+ this.shouldReconnect = true; // Flag to control auto-reconnect
428
429
 
429
430
  // Smart cache configuration
430
431
  // Size: 500MB - 2GB (default 500MB)
@@ -555,7 +556,11 @@ class SearchWorker {
555
556
  this.isConnected = false;
556
557
  this._stopHeartbeat();
557
558
  this.onDisconnected(this);
558
- this._scheduleReconnect();
559
+
560
+ // Only reconnect if flag is true (not manually disconnected)
561
+ if (this.shouldReconnect) {
562
+ this._scheduleReconnect();
563
+ }
559
564
  });
560
565
 
561
566
  this.ws.on('error', (error) => {
@@ -564,7 +569,9 @@ class SearchWorker {
564
569
 
565
570
  } catch (e) {
566
571
  this.onError(`Connection failed: ${e.message}`);
567
- this._scheduleReconnect();
572
+ if (this.shouldReconnect) {
573
+ this._scheduleReconnect();
574
+ }
568
575
  }
569
576
  }
570
577
 
@@ -599,7 +606,7 @@ class SearchWorker {
599
606
  // Invalidate a cache key
600
607
  if (message.key) {
601
608
  this.cache._evict(message.key, 'invalidate');
602
- this.onLog(`Cache invalidated: ${message.key.substring(0, 30)}...`);
609
+ // Privacy: Don't log cache keys
603
610
  }
604
611
  break;
605
612
 
@@ -640,7 +647,7 @@ class SearchWorker {
640
647
  value
641
648
  });
642
649
 
643
- this.onLog(`Cache HIT: ${key.substring(0, 30)}...`);
650
+ // Privacy: Don't log cache keys (they contain search queries)
644
651
  } else {
645
652
  this.stats.cacheMisses++;
646
653
 
@@ -669,8 +676,7 @@ class SearchWorker {
669
676
  this.stats.cacheStored++;
670
677
  this.onCacheStore(key);
671
678
 
672
- const cacheStats = this.cache.getStats();
673
- this.onLog(`Cached: ${key.substring(0, 30)}... (${cacheStats.entries} entries, ${cacheStats.sizeFormatted})`);
679
+ // Privacy: Don't log cache keys (they contain search queries)
674
680
  }
675
681
 
676
682
  // Send cache registry to coordinator
@@ -793,6 +799,11 @@ class SearchWorker {
793
799
 
794
800
  // Schedule reconnection
795
801
  _scheduleReconnect() {
802
+ // Check if reconnect is disabled (manual disconnect)
803
+ if (!this.shouldReconnect) {
804
+ return;
805
+ }
806
+
796
807
  if (this.reconnectTimeout) {
797
808
  clearTimeout(this.reconnectTimeout);
798
809
  }
@@ -814,6 +825,9 @@ class SearchWorker {
814
825
 
815
826
  // Disconnect from coordinator
816
827
  disconnect() {
828
+ // Disable auto-reconnect FIRST
829
+ this.shouldReconnect = false;
830
+
817
831
  this._stopHeartbeat();
818
832
 
819
833
  // Stop cache cleanup process
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avalw/search-worker",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "AVALW Distributed Cache Worker - Intelligent caching with size limits and auto-cleanup",
5
5
  "main": "index.js",
6
6
  "bin": {