@aichatwar/shared 1.0.104 → 1.0.106

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.
@@ -11,7 +11,9 @@ export declare abstract class Listener<T extends BaseEvent> {
11
11
  private readonly maxInitialRetries;
12
12
  private readonly maxRetryDelay;
13
13
  private isListening;
14
+ private crashHandlerSetup;
14
15
  constructor(consumer: Consumer);
16
+ private setupCrashHandler;
15
17
  ack(): Promise<void>;
16
18
  listen(): Promise<void>;
17
19
  }
@@ -14,10 +14,29 @@ class Listener {
14
14
  constructor(consumer) {
15
15
  this.ackDeadline = 5 * 1000; // 5 seconds
16
16
  this.retryCount = 0;
17
- this.maxInitialRetries = 5; // Show detailed retry logs for first 5 attempts
17
+ this.maxInitialRetries = 3; // Show detailed retry logs for first 3 attempts
18
18
  this.maxRetryDelay = 60000; // Cap delay at 60 seconds
19
19
  this.isListening = false; // Track if listener is active
20
+ this.crashHandlerSetup = false; // Track if crash handler has been set up
20
21
  this.consumer = consumer;
22
+ this.setupCrashHandler();
23
+ }
24
+ setupCrashHandler() {
25
+ // Only set up crash handler once to avoid memory leaks
26
+ if (this.crashHandlerSetup) {
27
+ return;
28
+ }
29
+ this.consumer.on('consumer.crash', (event) => {
30
+ var _a;
31
+ const error = event.payload.error;
32
+ if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('does not host this topic-partition')) {
33
+ console.warn(`[${this.topic}] Consumer partition error (non-fatal):`, error.message);
34
+ // Don't crash - this is often a transient error
35
+ return;
36
+ }
37
+ console.error(`[${this.topic}] Consumer crashed:`, error);
38
+ });
39
+ this.crashHandlerSetup = true;
21
40
  }
22
41
  // Manual acknowledgment method
23
42
  ack() {
@@ -42,17 +61,7 @@ class Listener {
42
61
  }
43
62
  try {
44
63
  yield this.consumer.connect();
45
- // Handle consumer errors (including partition errors)
46
- this.consumer.on('consumer.crash', (event) => {
47
- var _a;
48
- const error = event.payload.error;
49
- if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('does not host this topic-partition')) {
50
- console.warn(`[${this.topic}] Consumer partition error (non-fatal):`, error.message);
51
- // Don't crash - this is often a transient error
52
- return;
53
- }
54
- console.error(`[${this.topic}] Consumer crashed:`, error);
55
- });
64
+ // Crash handler is set up in constructor, no need to add it again
56
65
  yield this.consumer.subscribe({
57
66
  topic: this.topic,
58
67
  fromBeginning: false,
@@ -99,11 +108,11 @@ class Listener {
99
108
  const delay = Math.min(5000 * Math.pow(2, Math.min(this.retryCount - 1, 6)), this.maxRetryDelay);
100
109
  // Show detailed logs for first few attempts, then less frequently
101
110
  if (this.retryCount <= this.maxInitialRetries) {
102
- console.warn(`[${this.topic}] Topic partition error (attempt ${this.retryCount}/${this.maxInitialRetries}): ${error.message}. Retrying in ${delay}ms...`);
111
+ console.warn(`[${this.topic}] Topic partition error (attempt ${this.retryCount}/${this.maxInitialRetries}, will continue indefinitely): ${error.message}. Retrying in ${delay}ms...`);
103
112
  }
104
113
  else if (this.retryCount % 10 === 0) {
105
114
  // Log every 10th retry after initial attempts to avoid log spam
106
- console.warn(`[${this.topic}] Still retrying subscription (attempt ${this.retryCount}). Topic may not exist yet or has no data. Retrying in ${delay}ms...`);
115
+ console.warn(`[${this.topic}] Still retrying subscription (attempt ${this.retryCount}, retrying indefinitely). Topic may not exist yet or has no data. Retrying in ${delay}ms...`);
107
116
  }
108
117
  // Retry indefinitely with exponential backoff
109
118
  // This allows the listener to connect once the topic becomes available
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aichatwar/shared",
3
- "version": "1.0.104",
3
+ "version": "1.0.106",
4
4
  "main": "./build/index.js",
5
5
  "typs": "./build/index.d.ts",
6
6
  "files": [