@onlineapps/conn-infra-mq 1.1.34 → 1.1.35
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/package.json +1 -1
- package/src/layers/QueueManager.js +21 -11
package/package.json
CHANGED
|
@@ -249,27 +249,37 @@ class QueueManager {
|
|
|
249
249
|
for (const queueInfo of queueNames) {
|
|
250
250
|
// CRITICAL: Check if channel is closed before each queue operation (may have been closed by previous 406)
|
|
251
251
|
// Channel closes SYNCHRONOUSLY on 406, so we must check before each assertQueue
|
|
252
|
+
// amqplib's channel.closed may be undefined, so we test by trying a no-op operation
|
|
252
253
|
if (!channel) {
|
|
253
254
|
console.warn(`[QueueManager] DEBUG: Channel is null before ${queueInfo.name}, recreating...`);
|
|
254
255
|
channel = await transport._connection.createChannel();
|
|
255
256
|
transport.queueChannel = channel;
|
|
256
257
|
console.log(`[QueueManager] DEBUG: Channel recreated (was null) before ${queueInfo.name}`);
|
|
257
258
|
} else {
|
|
258
|
-
//
|
|
259
|
+
// Test if channel is usable by trying a no-op (checkQueue on a known queue)
|
|
260
|
+
// This will throw if channel is closed
|
|
261
|
+
let channelUsable = false;
|
|
259
262
|
try {
|
|
260
|
-
// Try a
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
// Try to check a queue that definitely exists (workflow.init) - this tests channel usability
|
|
264
|
+
// If channel is closed, this will throw immediately
|
|
265
|
+
await channel.checkQueue('workflow.init');
|
|
266
|
+
channelUsable = true;
|
|
267
|
+
console.log(`[QueueManager] DEBUG: Channel is usable before ${queueInfo.name}`);
|
|
268
|
+
} catch (testErr) {
|
|
269
|
+
// Channel is closed or unusable - recreate it
|
|
270
|
+
console.warn(`[QueueManager] DEBUG: Channel test failed before ${queueInfo.name} (${testErr.message}), recreating...`);
|
|
271
|
+
try {
|
|
263
272
|
channel = await transport._connection.createChannel();
|
|
264
273
|
transport.queueChannel = channel;
|
|
265
|
-
console.log(`[QueueManager] DEBUG: Channel recreated (
|
|
274
|
+
console.log(`[QueueManager] DEBUG: Channel recreated (test failed) before ${queueInfo.name}`);
|
|
275
|
+
channelUsable = true;
|
|
276
|
+
} catch (recreateErr) {
|
|
277
|
+
throw new Error(`Failed to recreate channel before ${queueInfo.name}: ${recreateErr.message}`);
|
|
266
278
|
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
transport.queueChannel = channel;
|
|
272
|
-
console.log(`[QueueManager] DEBUG: Channel recreated (check failed) before ${queueInfo.name}`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!channelUsable) {
|
|
282
|
+
throw new Error(`Channel is not usable before ${queueInfo.name} and recreation failed`);
|
|
273
283
|
}
|
|
274
284
|
}
|
|
275
285
|
|