Skip to content

Commit d6c64ca

Browse files
authored
fix(amqplib): prevent crash when basic.get returns no message (#6686)
1 parent 8900c5c commit d6c64ca

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/datadog-plugin-amqplib/src/consumer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AmqplibConsumerPlugin extends ConsumerPlugin {
1010
static operation = 'consume'
1111

1212
bindStart (ctx) {
13-
const { method, fields, message, queue } = ctx
13+
const { method, fields = {}, message, queue } = ctx
1414

1515
if (method !== 'basic.deliver' && method !== 'basic.get') return
1616

packages/datadog-plugin-amqplib/test/index.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,18 @@ describe('Plugin', () => {
478478
})
479479
})
480480

481+
it('regression test: should handle basic.get when queue is empty', done => {
482+
channel.assertQueue(queue, {}, (err, ok) => {
483+
if (err) return done(err)
484+
485+
channel.get(ok.queue, {}, (err, msg) => {
486+
if (err) return done(err)
487+
expect(msg).to.equal(false)
488+
done()
489+
})
490+
})
491+
})
492+
481493
it('Should set pathway hash tag on a span when producing', (done) => {
482494
channel.assertQueue(queue, {}, (err, ok) => {
483495
if (err) return done(err)

0 commit comments

Comments
 (0)