@aichatwar/shared 1.0.104 → 1.0.105

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
  }
@@ -17,7 +17,26 @@ class Listener {
17
17
  this.maxInitialRetries = 5; // Show detailed retry logs for first 5 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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aichatwar/shared",
3
- "version": "1.0.104",
3
+ "version": "1.0.105",
4
4
  "main": "./build/index.js",
5
5
  "typs": "./build/index.d.ts",
6
6
  "files": [