From d49e5d168e19d54b12f173476352843f425933e5 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 20 May 2026 13:22:38 +0200 Subject: [PATCH] test(node-integration): Retry RabbitMQ connect in amqplib scenario Fixes #20969 --- .../suites/tracing/amqplib/scenario.mjs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/tracing/amqplib/scenario.mjs b/dev-packages/node-integration-tests/suites/tracing/amqplib/scenario.mjs index de526e42aef8..e5aeff07ad69 100644 --- a/dev-packages/node-integration-tests/suites/tracing/amqplib/scenario.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/amqplib/scenario.mjs @@ -35,9 +35,26 @@ const QUEUE_OPTIONS = { })(); async function connectToRabbitMQ() { - const connection = await amqp.connect(AMQP_URL); - const channel = await connection.createChannel(); - return { connection, channel }; + // Retry up to 5 times with 1s backoff. The docker-compose healthcheck + // (`rabbitmq-diagnostics -q ping`) reports the broker ready before AMQP + // handshakes actually succeed, so the first connect can race with broker + // boot and reject with "Socket closed abruptly during opening handshake". + // That rejection becomes an unhandled rejection captured by Sentry and + // sent as an error envelope, which the runner sees ahead of the expected + // transaction and reports as "Expected envelope item type 'transaction' + // but got 'event'" (the flake reported in the issue). + let lastError; + for (let attempt = 0; attempt < 5; attempt++) { + try { + const connection = await amqp.connect(AMQP_URL); + const channel = await connection.createChannel(); + return { connection, channel }; + } catch (err) { + lastError = err; + await new Promise(resolve => setTimeout(resolve, 1000)); + } + } + throw lastError; } async function createQueue(queueName, channel) {