amqplib 1.0.3 → 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.
@@ -9,7 +9,7 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  services:
11
11
  rabbitmq:
12
- image: rabbitmq:3-alpine
12
+ image: rabbitmq:4.2-alpine
13
13
  ports:
14
14
  - 5672:5672
15
15
 
@@ -14,7 +14,7 @@ jobs:
14
14
  runs-on: ubuntu-latest
15
15
  services:
16
16
  rabbitmq:
17
- image: rabbitmq:3.12-alpine
17
+ image: rabbitmq:4.2-alpine
18
18
  ports:
19
19
  - 5672:5672
20
20
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## v1.0.3
4
9
  - Fix AssertionError crash when backpressure occurs while draining newStreams in Mux (fixes #841)
5
10
 
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
 
@@ -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 Channel.prototype.publish.call(this, exchange, routingKey, content, options);
251
+ return result;
251
252
  }
252
253
 
253
254
  sendToQueue(queue, content, options, cb) {
@@ -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 super.publish(exchange, routingKey, content, options);
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/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.3",
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": "make 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', () => {
@@ -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() {
@@ -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', () => {