amqplib 1.0.2 → 1.0.4
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/.github/workflows/publish.yml +1 -1
- package/.github/workflows/test.yml +1 -1
- package/CHANGELOG.md +8 -0
- package/Makefile +3 -3
- package/lib/callback_model.js +2 -1
- package/lib/channel_model.js +2 -1
- package/lib/connection.js +10 -0
- package/lib/mux.js +2 -3
- package/package.json +5 -3
- package/test/callback_api.test.js +11 -0
- package/test/channel_api.test.js +11 -0
- package/test/connection.test.js +20 -0
- package/test/mux.test.js +43 -0
- package/.claude/settings.local.json +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change log for amqplib
|
|
2
2
|
|
|
3
|
+
## v1.0.4
|
|
4
|
+
- Updated build to use RabbitMQ 4.2
|
|
5
|
+
- Fix memory leak in ConfirmChannel.publish when channel is already closed (fixes #842)
|
|
6
|
+
- Close connection immediately when close() is called while the connection is blocked (fixes #744)
|
|
7
|
+
|
|
8
|
+
## v1.0.3
|
|
9
|
+
- Fix AssertionError crash when backpressure occurs while draining newStreams in Mux (fixes #841)
|
|
10
|
+
|
|
3
11
|
## v1.0.2
|
|
4
12
|
- Replace url-parse with WHATWG URL API
|
|
5
13
|
|
package/Makefile
CHANGED
|
@@ -13,16 +13,16 @@ error:
|
|
|
13
13
|
@exit 1
|
|
14
14
|
|
|
15
15
|
test:
|
|
16
|
-
node --test
|
|
16
|
+
node --test --test-reporter=spec
|
|
17
17
|
|
|
18
18
|
test-all-nodejs:
|
|
19
19
|
for v in $(NODEJS_VERSIONS); \
|
|
20
20
|
do echo "-- Node version $$v --"; \
|
|
21
|
-
nave use $$v node --test; \
|
|
21
|
+
nave use $$v node --test --test-reporter=spec; \
|
|
22
22
|
done
|
|
23
23
|
|
|
24
24
|
coverage:
|
|
25
|
-
node --test --test-coverage
|
|
25
|
+
node --test --test-coverage --test-reporter=spec
|
|
26
26
|
|
|
27
27
|
lib/defs.js: clean bin/generate-defs test
|
|
28
28
|
|
package/lib/callback_model.js
CHANGED
|
@@ -246,8 +246,9 @@ function callbackWrapper(_ch, cb) {
|
|
|
246
246
|
|
|
247
247
|
class ConfirmChannel extends Channel {
|
|
248
248
|
publish(exchange, routingKey, content, options, cb) {
|
|
249
|
+
const result = Channel.prototype.publish.call(this, exchange, routingKey, content, options);
|
|
249
250
|
this.pushConfirmCallback(cb);
|
|
250
|
-
return
|
|
251
|
+
return result;
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
sendToQueue(queue, content, options, cb) {
|
package/lib/channel_model.js
CHANGED
|
@@ -224,8 +224,9 @@ Channel.prototype.prefetch = Channel.prototype.qos;
|
|
|
224
224
|
|
|
225
225
|
class ConfirmChannel extends Channel {
|
|
226
226
|
publish(exchange, routingKey, content, options, cb) {
|
|
227
|
+
const result = super.publish(exchange, routingKey, content, options);
|
|
227
228
|
this.pushConfirmCallback(cb);
|
|
228
|
-
return
|
|
229
|
+
return result;
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
sendToQueue(queue, content, options, cb) {
|
package/lib/connection.js
CHANGED
|
@@ -41,6 +41,7 @@ class Connection extends EventEmitter {
|
|
|
41
41
|
this.recvSinceLastCheck = false;
|
|
42
42
|
|
|
43
43
|
this.expectSocketClose = false;
|
|
44
|
+
this.blocked = false;
|
|
44
45
|
this.freeChannels = new BitSet();
|
|
45
46
|
this.channels = [
|
|
46
47
|
{
|
|
@@ -301,6 +302,13 @@ class Connection extends EventEmitter {
|
|
|
301
302
|
toClosing(capturedStack, k) {
|
|
302
303
|
const send = this.sendMethod.bind(this);
|
|
303
304
|
|
|
305
|
+
if (this.blocked) {
|
|
306
|
+
if (k) k();
|
|
307
|
+
const s = stackCapture('Connection blocked: closing immediately');
|
|
308
|
+
this.toClosed(s, undefined);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
304
312
|
this.accept = function (f) {
|
|
305
313
|
if (f.id === defs.ConnectionCloseOk) {
|
|
306
314
|
if (k) k();
|
|
@@ -581,8 +589,10 @@ function channel0(connection) {
|
|
|
581
589
|
}
|
|
582
590
|
connection.toClosed(s, e);
|
|
583
591
|
} else if (f.id === defs.ConnectionBlocked) {
|
|
592
|
+
connection.blocked = true;
|
|
584
593
|
connection.emit('blocked', f.fields.reason);
|
|
585
594
|
} else if (f.id === defs.ConnectionUnblocked) {
|
|
595
|
+
connection.blocked = false;
|
|
586
596
|
connection.emit('unblocked');
|
|
587
597
|
} else if (f.id === defs.ConnectionUpdateSecretOk) {
|
|
588
598
|
connection.emit('update-secret-ok');
|
package/lib/mux.js
CHANGED
|
@@ -40,14 +40,13 @@ class Mux {
|
|
|
40
40
|
// Try to read a chunk from each stream in turn, until all streams
|
|
41
41
|
// are empty, or we exhaust our ability to accept chunks.
|
|
42
42
|
function roundrobin(streams) {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
while (accepting && streams.length > 0) {
|
|
44
|
+
const stream = streams.shift();
|
|
45
45
|
const chunk = stream.read();
|
|
46
46
|
if (chunk !== null) {
|
|
47
47
|
accepting = out.write(chunk);
|
|
48
48
|
streams.push(stream);
|
|
49
49
|
}
|
|
50
|
-
stream = streams.shift();
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "amqplib",
|
|
3
3
|
"homepage": "http://amqp-node.github.io/amqplib/",
|
|
4
4
|
"main": "./channel_api.js",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.4",
|
|
6
6
|
"description": "An AMQP 0-9-1 (e.g., RabbitMQ) library and client.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
"uglify-js": "2.8.x"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"test": "
|
|
25
|
-
"test:only": "node --test --test-only",
|
|
24
|
+
"test": "node --test --test-timeout=1000",
|
|
25
|
+
"test:only": "node --test --test-only --test-timeout=1000",
|
|
26
|
+
"rabbitmq-3": "docker run -d --rm --name rabbitmq -p 5672:5672 rabbitmq:3.12-alpine",
|
|
27
|
+
"rabbitmq-4": "docker run -d --rm --name rabbitmq -p 5672:5672 rabbitmq:4.2-alpine",
|
|
26
28
|
"format": "biome format . --write",
|
|
27
29
|
"lint": "biome lint --max-diagnostics=1000 ."
|
|
28
30
|
},
|
|
@@ -305,6 +305,17 @@ describe('Callback API', () => {
|
|
|
305
305
|
done();
|
|
306
306
|
});
|
|
307
307
|
});
|
|
308
|
+
|
|
309
|
+
confirm_channel_test('publish on closed channel does not leak callbacks', (_ch, done) => {
|
|
310
|
+
ch = _ch;
|
|
311
|
+
ch.close(() => {
|
|
312
|
+
for (let i = 0; i < 10; i++) {
|
|
313
|
+
try { ch.publish('', '', Buffer.from('x'), {}, () => {}); } catch (_) {}
|
|
314
|
+
}
|
|
315
|
+
assert.strictEqual(ch.unconfirmed.length, 0);
|
|
316
|
+
done();
|
|
317
|
+
});
|
|
318
|
+
});
|
|
308
319
|
});
|
|
309
320
|
|
|
310
321
|
describe('Error handling', () => {
|
package/test/channel_api.test.js
CHANGED
|
@@ -499,6 +499,17 @@ describe('confirms', () => {
|
|
|
499
499
|
}));
|
|
500
500
|
});
|
|
501
501
|
});
|
|
502
|
+
|
|
503
|
+
it('publish on closed channel does not leak callbacks', () => {
|
|
504
|
+
return withConfirmChannel((ch) => {
|
|
505
|
+
return ch.close().then(() => {
|
|
506
|
+
for (let i = 0; i < 10; i++) {
|
|
507
|
+
try { ch.publish('', '', Buffer.from('x'), {}, () => {}); } catch (_) {}
|
|
508
|
+
}
|
|
509
|
+
assert.strictEqual(ch.unconfirmed.length, 0);
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
});
|
|
502
513
|
});
|
|
503
514
|
|
|
504
515
|
function connect() {
|
package/test/connection.test.js
CHANGED
|
@@ -278,6 +278,26 @@ describe('Connection', () => {
|
|
|
278
278
|
.then(() => send(defs.ConnectionCloseOk, {}))
|
|
279
279
|
.then(cb, cb);
|
|
280
280
|
}));
|
|
281
|
+
|
|
282
|
+
it('close while blocked closes immediately', connectionTest((c, cb) => {
|
|
283
|
+
const decrementLatch = latch(2, cb);
|
|
284
|
+
c.on('close', () => decrementLatch());
|
|
285
|
+
c.open(OPEN_OPTS, (err) => {
|
|
286
|
+
assert.ifError(err);
|
|
287
|
+
c.once('blocked', () => {
|
|
288
|
+
c.close((err) => {
|
|
289
|
+
assert.ifError(err);
|
|
290
|
+
decrementLatch();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}, (send, wait, cb) => {
|
|
295
|
+
handshake(send, wait)
|
|
296
|
+
.then(() => send(defs.ConnectionBlocked, { reason: 'memory' }, 0))
|
|
297
|
+
.then(wait(defs.ConnectionClose))
|
|
298
|
+
// deliberately do NOT send ConnectionCloseOk — client must close anyway
|
|
299
|
+
.then(cb, cb);
|
|
300
|
+
}));
|
|
281
301
|
});
|
|
282
302
|
|
|
283
303
|
describe('heartbeats', () => {
|
package/test/mux.test.js
CHANGED
|
@@ -184,6 +184,49 @@ describe('mux', () => {
|
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
it('backpressure does not crash when newStreams is drained', () => {
|
|
188
|
+
// Regression test: out.write() returns false (backpressure) while
|
|
189
|
+
// draining newStreams. The buggy code does an unconditional shift at the
|
|
190
|
+
// bottom of the loop, so if the next stream reads null (empty) it gets
|
|
191
|
+
// discarded without being pushed back, leaving newStreams empty and
|
|
192
|
+
// triggering assert(this.newStreams.length > 0) in the else-branch.
|
|
193
|
+
//
|
|
194
|
+
// Scenario: newStreams = [input1, input2], input1 has data, input2 empty.
|
|
195
|
+
// - shift input1, read 1, write → backpressure (false), push input1 back
|
|
196
|
+
// - (buggy) unconditional shift takes input2, loop condition false → exit
|
|
197
|
+
// - newStreams = [input1], length > 0, assert passes ← not the bug path
|
|
198
|
+
//
|
|
199
|
+
// The crash path requires backpressure AND the shifted stream reading null
|
|
200
|
+
// with no other streams remaining. Use a single stream that has data, then
|
|
201
|
+
// engineer a second read() on the same stream returning null after the
|
|
202
|
+
// write so the stream is not pushed back, emptying newStreams entirely.
|
|
203
|
+
const input1 = stream();
|
|
204
|
+
const output = stream();
|
|
205
|
+
const mux = new Mux(output);
|
|
206
|
+
|
|
207
|
+
mux.newStreams.push(input1);
|
|
208
|
+
input1.write(1);
|
|
209
|
+
|
|
210
|
+
// After the first write (which triggers backpressure), wrap read() so
|
|
211
|
+
// the stream appears empty on the next call — simulating a stream that
|
|
212
|
+
// had one item buffered and is now drained within the same roundrobin pass.
|
|
213
|
+
const originalRead = input1.read.bind(input1);
|
|
214
|
+
let readCount = 0;
|
|
215
|
+
input1.read = (size) => {
|
|
216
|
+
readCount++;
|
|
217
|
+
if (readCount > 1) return null; // appear empty after first read
|
|
218
|
+
return originalRead(size);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const originalWrite = output.write.bind(output);
|
|
222
|
+
output.write = (...args) => {
|
|
223
|
+
originalWrite(...args);
|
|
224
|
+
return false; // signal backpressure immediately
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
assert.doesNotThrow(() => mux._readIncoming());
|
|
228
|
+
});
|
|
229
|
+
|
|
187
230
|
it('roundrobin', (_t, done) => {
|
|
188
231
|
const input1 = stream();
|
|
189
232
|
const input2 = stream();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(npx oxlint:*)",
|
|
5
|
-
"Bash(npm t)",
|
|
6
|
-
"Bash(git add:*)",
|
|
7
|
-
"Bash(git commit:*)",
|
|
8
|
-
"Bash(npm run lint:*)",
|
|
9
|
-
"Bash(git checkout:*)",
|
|
10
|
-
"Bash(npx biome lint:*)",
|
|
11
|
-
"Bash(node:*)"
|
|
12
|
-
],
|
|
13
|
-
"deny": [],
|
|
14
|
-
"ask": []
|
|
15
|
-
}
|
|
16
|
-
}
|