diff --git a/.changeset/bump-bullmq-v6.md b/.changeset/bump-bullmq-v6.md new file mode 100644 index 0000000..c5ca40e --- /dev/null +++ b/.changeset/bump-bullmq-v6.md @@ -0,0 +1,5 @@ +--- +'@crypt.fyi/server': patch +--- + +Upgrade bullmq to v6 to pick up security fixes. diff --git a/packages/server/package.json b/packages/server/package.json index 0dca673..272f469 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -63,7 +63,7 @@ "@opentelemetry/sdk-node": "^0.223.0", "@opentelemetry/sdk-trace-base": "^2.0.1", "@opentelemetry/semantic-conventions": "^1.36.0", - "bullmq": "^5.58.3", + "bullmq": "^6.7.1", "bytes": "^3.1.2", "fastify": "^5.12.5", "fastify-type-provider-zod": "^5.0.3", diff --git a/packages/server/src/rotate-keys.ts b/packages/server/src/rotate-keys.ts index 72baf45..b3aa78a 100644 --- a/packages/server/src/rotate-keys.ts +++ b/packages/server/src/rotate-keys.ts @@ -12,7 +12,7 @@ import { Queue } from 'bullmq'; import { machine } from '@crypt.fyi/core'; import { config } from './config.js'; import { rotateVaultKeys, countWebhookJobsOnPreviousKeys } from './vault/rotate.js'; -import { WEBHOOK_QUEUE_NAME } from './webhook.js'; +import { WEBHOOK_QUEUE_NAME, toBullMQConnection } from './webhook.js'; const JOB_PAGE_SIZE = 500; @@ -26,12 +26,14 @@ const main = async () => { let webhookJobsOnPreviousKeys = 0; if (config.webhookSender === 'bullmq') { - const queue = new Queue(WEBHOOK_QUEUE_NAME, { connection: redis.options }); + const queue = new Queue(WEBHOOK_QUEUE_NAME, { + connection: toBullMQConnection(redis), + }); try { // Paged per state so a large backlog never has to fit in memory at once. // Jobs moving between states mid-count can be missed or counted twice; // rerunning before removing a key covers that. - for (const state of ['waiting', 'delayed', 'active', 'paused', 'prioritized'] as const) { + for (const state of ['waiting', 'delayed', 'active', 'prioritized'] as const) { for (let start = 0; ; start += JOB_PAGE_SIZE) { const jobs = await queue.getJobs([state], start, start + JOB_PAGE_SIZE - 1); webhookJobsOnPreviousKeys += await countWebhookJobsOnPreviousKeys( diff --git a/packages/server/src/webhook.ts b/packages/server/src/webhook.ts index 8402154..fbd9359 100644 --- a/packages/server/src/webhook.ts +++ b/packages/server/src/webhook.ts @@ -1,4 +1,4 @@ -import { Queue, Worker } from 'bullmq'; +import { Queue, Worker, type RedisOptions } from 'bullmq'; import { machine, isRetryableFetchError } from '@crypt.fyi/core'; import type { Logger } from './logging.js'; import { Redis } from 'ioredis'; @@ -18,6 +18,17 @@ const messageSchema = z.object({ export type Message = z.infer; export const WEBHOOK_QUEUE_NAME = 'webhooks'; + +/** + * Connection options for a BullMQ Queue/Worker derived from an ioredis client. + * Passing options rather than the client keeps each Queue/Worker on its own + * connections, so closing them never races with the caller quitting `redis`. + * ioredis types `retryStrategy` as nullable but BullMQ v6 does not accept null. + */ +export const toBullMQConnection = (redis: Redis): RedisOptions => { + const { retryStrategy, ...options } = redis.options; + return { ...options, retryStrategy: retryStrategy ?? undefined }; +}; const JOB_NAME = 'webhook'; export interface WebhookSender { @@ -66,8 +77,9 @@ export const createBullMQWebhookSender = ({ fetchFn = fetch, shouldRetry = isRetryableFetchError, }: BullMQWebhookSenderOptions): { webhookSender: WebhookSender; cleanup: () => Promise } => { + const connection = toBullMQConnection(redis); const queue = new Queue(WEBHOOK_QUEUE_NAME, { - connection: redis.options, + connection, streams: { events: { maxLen: streamEventsMaxLength, @@ -138,7 +150,7 @@ export const createBullMQWebhookSender = ({ clearTimeout(timeoutId); } }, - { connection: redis.options, concurrency, drainDelay: Math.round(drainDelayMs / 1000) }, + { connection, concurrency, drainDelay: Math.round(drainDelayMs / 1000) }, ); worker.on('failed', async (job, error) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47e3b2e..a62f0da 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -332,8 +332,8 @@ importers: specifier: ^1.36.0 version: 1.43.0 bullmq: - specifier: ^5.58.3 - version: 5.81.2(supports-color@10.2.2) + specifier: ^6.7.1 + version: 6.7.8(ioredis@5.11.1(supports-color@10.2.2)) bytes: specifier: ^3.1.2 version: 3.1.2 @@ -1822,33 +1822,33 @@ packages: '@manypkg/get-packages@1.1.3': resolution: {integrity: sha512-fo+QhuU3qE/2TQMQmbVMqaQ6EWbMhi4ABWP+O4AM1NqPBuy0OrApV5LO6BrrgnhtAHS2NH6RrVk9OL181tTi8A==} - '@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.4': - resolution: {integrity: sha512-LCkGo6JDfaBhgST7UpPWgNgLINpcpabaHfyz5OBx75nUYxBsaEPxjnyNjWpeb/xBup/682QnBfRBy2/LvPutZQ==} + '@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.7': + resolution: {integrity: sha512-2zPHLn+MuGJ6GP/5jDrwa9Jy0CI+D3Ibpvopf5SFfmc1G9gdofR4uB7YrJAAp4vodn/7iDOciyv8bgkRPLw7cA==} cpu: [arm64] os: [darwin] - '@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.4': - resolution: {integrity: sha512-zExlW9zUJKZH/tOtVMttwjKa4Xm/3KcNjnE3dPN92uCktwavMxpgCA3MoJK/DOnTWsQgo224OaST27/mPNAf+w==} + '@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.7': + resolution: {integrity: sha512-of1miwFfEdgs5nythewsEoocfpbjzUf8PC996YDe3kAyv0ZJiMJs5NXlYhE6IdjxfNEPqUXj/BYBnpD8kRdfeQ==} cpu: [x64] os: [darwin] - '@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.4': - resolution: {integrity: sha512-dgX0P/9wGPJeHFBG+ZmhgE6bmtMt7NP5CRBGyyktpopdk/mW4POnrpQsSLtKI1dwpc+pPLuXHDh6vvskyQE/sw==} + '@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.7': + resolution: {integrity: sha512-jcRydYARTW0gX5idJhxV7m3KkRUD7KtZLYFF1ZY18HrPqpGY0TCqPUTJCwka2kVfVOwfKs3ZmlPSmQb4S6xj7w==} cpu: [arm64] os: [linux] - '@msgpackr-extract/msgpackr-extract-linux-arm@3.0.4': - resolution: {integrity: sha512-Tg3yX65f5GbtXLkrYEHE5oibZG9epyYWas7FogTTEJeDEF9JlXJzKgXaNhT3UXlTOeA+AfZpYZYZ0uPj7Cfquw==} + '@msgpackr-extract/msgpackr-extract-linux-arm@3.0.7': + resolution: {integrity: sha512-aDPbiEkFHs3H68705JKxJ15IT41wFdvDhba1pL8ygfdoshboL5dsXtiu76/CqhLWYneE+9hwBE+0abqNOiQ4Bw==} cpu: [arm] os: [linux] - '@msgpackr-extract/msgpackr-extract-linux-x64@3.0.4': - resolution: {integrity: sha512-8TNXMEjJc3QEy7R/x1INhgiU+XakDAFUzBhaz7+Rbrs8NH5UQeHQxxmzsSBJGyV6I1jW79undiQm8tOI+D+8FQ==} + '@msgpackr-extract/msgpackr-extract-linux-x64@3.0.7': + resolution: {integrity: sha512-A9xOmARctmUvHrBj5GGzGAigsZFnqE4kld5oprX3PyPbkVALV4jwBc17gPZrhSOvnXQc81hE9K7S2hDUCgialA==} cpu: [x64] os: [linux] - '@msgpackr-extract/msgpackr-extract-win32-x64@3.0.4': - resolution: {integrity: sha512-CmCXPQrkbwExx3j946/PtHWHbYJiCRBRDl4BlkRQcJB/YOwQxJRTpoo7aTsortjgoJ1x7opzTSxn7C+ASSLVjQ==} + '@msgpackr-extract/msgpackr-extract-win32-x64@3.0.7': + resolution: {integrity: sha512-PRBiOqK4mcR0rvm6nybO7pSOYRR2Zza0+43UK2IvbVGelzMqZViiZJmOWGuWOX678QKESO6YrHx36z43nSS6iQ==} cpu: [x64] os: [win32] @@ -4135,12 +4135,21 @@ packages: buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} - bullmq@5.81.2: - resolution: {integrity: sha512-Hi9GaVCC6HE9bQP65j/FNv1aL1fcEukTF99ezS5pl1Ud+joCFpNWiPCV45mWdkEmpuacS0XJdMMFGKPIHCwoPg==} - engines: {node: '>=12.22.0'} + bullmq@6.7.8: + resolution: {integrity: sha512-Mt0+nKGNFWAruuwwzEUVE+5yEgK5XgzjoR2BjSKp/JeqfgeYO0pFh6oy78Ls8u9upVTsaLhBzSaEZAhYvjPlJg==} + engines: {node: '>=14.18.0'} peerDependencies: + bullmq-otel: '>=2.0.0' + ioredis: '>=5.0.0' + pg: '>=8.0.0' redis: '>=5.0.0' peerDependenciesMeta: + bullmq-otel: + optional: true + ioredis: + optional: true + pg: + optional: true redis: optional: true @@ -4369,10 +4378,9 @@ packages: create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - cron-parser@4.9.0: - resolution: {integrity: sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q==} - engines: {node: '>=12.0.0'} - deprecated: v4 is no longer maintained, upgrade to v5 + cron-parser@5.10.6: + resolution: {integrity: sha512-kpoxgQyveO1l29nw+FWdvmotyV7eOSzGHQpxiXOEZIDOjqO1iR6kfgJ0PVHTuV26uBemKq3ppzma7dHFAG7viw==} + engines: {node: '>=18'} cross-env@10.1.0: resolution: {integrity: sha512-GsYosgnACZTADcmEyJctkJIoqAhHjttw7RsFrVoJNXbsWWqaq6Ym+7kZjq6mS45O0jij6vtiReppKQEtqWy6Dw==} @@ -5843,12 +5851,12 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - msgpackr-extract@3.0.4: - resolution: {integrity: sha512-4kmO/MdyUIkLIvTPr8VHLil4AtoKIoniWPIEk5+CDy0xnWC84azhSFmuJ7PxZdsYtiP5kEeQsORAVIeMgxT+Hw==} + msgpackr-extract@3.0.7: + resolution: {integrity: sha512-/dOQboWnkR1cjm88XyH/cGSivECGgyQu3814+bNUAq5wACQC8Ya/CViB9WApvWJ5Hya/JJQQmUeBFOZj8MLjGA==} hasBin: true - msgpackr@2.0.4: - resolution: {integrity: sha512-o1C5KRmuRt+apqMr1HuGSqWStZoRBUpEsCsl15uM9VdAF1qHLtvMOU2En747EnTyEl6c4pzPewRMFF31s1CNbA==} + msgpackr@2.1.4: + resolution: {integrity: sha512-TvP18sX5U3MXoHHSUZen/FagaNTEJObyb8OlnJcNbqN6Ux/oCwYJrHhCOzi31bItyW/Efz1IDnRDKQ23j4ZuvA==} multimatch@6.0.0: resolution: {integrity: sha512-I7tSVxHGPlmPN/enE3mS1aOSo6bWBfls+3HmuEeCUBCE7gWnm3cBXCBkpurzFjVRwC6Kld8lLaZ1Iv5vOcjvcQ==} @@ -6500,6 +6508,11 @@ packages: engines: {node: '>=10'} hasBin: true + semver@7.8.6: + resolution: {integrity: sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==} + engines: {node: '>=10'} + hasBin: true + seroval-plugins@1.7.7: resolution: {integrity: sha512-5PAKQPAfj2MD332QeCdzXKm334ftIb0B1Ek3I9IQa73rPOlBSHko9mODFo8XNjzs6KJQG3nE6dn9dw7hJjrZAQ==} engines: {node: '>=20'} @@ -6874,6 +6887,9 @@ packages: tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} + tslib@2.9.1: + resolution: {integrity: sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==} + tsup@8.5.0: resolution: {integrity: sha512-VmBp77lWNQq6PfuMqCHD3xWl22vEoWsKajkF8t+yMBawlUS8JzEI+vOVMeuNZIuMML8qXRizFKi9oD5glKQVcQ==} engines: {node: '>=18'} @@ -8804,22 +8820,22 @@ snapshots: globby: 11.1.0 read-yaml-file: 1.1.0 - '@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.4': + '@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.7': optional: true - '@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.4': + '@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.7': optional: true - '@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.4': + '@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.7': optional: true - '@msgpackr-extract/msgpackr-extract-linux-arm@3.0.4': + '@msgpackr-extract/msgpackr-extract-linux-arm@3.0.7': optional: true - '@msgpackr-extract/msgpackr-extract-linux-x64@3.0.4': + '@msgpackr-extract/msgpackr-extract-linux-x64@3.0.7': optional: true - '@msgpackr-extract/msgpackr-extract-win32-x64@3.0.4': + '@msgpackr-extract/msgpackr-extract-win32-x64@3.0.7': optional: true '@napi-rs/wasm-runtime@1.1.6(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)': @@ -11184,16 +11200,15 @@ snapshots: base64-js: 1.5.1 ieee754: 1.2.1 - bullmq@5.81.2(supports-color@10.2.2): + bullmq@6.7.8(ioredis@5.11.1(supports-color@10.2.2)): dependencies: - cron-parser: 4.9.0 - ioredis: 5.11.1(supports-color@10.2.2) - msgpackr: 2.0.4 + cron-parser: 5.10.6 + msgpackr: 2.1.4 node-abort-controller: 3.1.1 - semver: 7.8.5 - tslib: 2.8.1 - transitivePeerDependencies: - - supports-color + semver: 7.8.6 + tslib: 2.9.1 + optionalDependencies: + ioredis: 5.11.1(supports-color@10.2.2) bundle-require@5.1.0(esbuild@0.25.0): dependencies: @@ -11408,7 +11423,7 @@ snapshots: create-require@1.1.1: {} - cron-parser@4.9.0: + cron-parser@5.10.6: dependencies: luxon: 3.7.2 @@ -12987,21 +13002,21 @@ snapshots: ms@2.1.3: {} - msgpackr-extract@3.0.4: + msgpackr-extract@3.0.7: dependencies: node-gyp-build-optional-packages: 5.2.2 optionalDependencies: - '@msgpackr-extract/msgpackr-extract-darwin-arm64': 3.0.4 - '@msgpackr-extract/msgpackr-extract-darwin-x64': 3.0.4 - '@msgpackr-extract/msgpackr-extract-linux-arm': 3.0.4 - '@msgpackr-extract/msgpackr-extract-linux-arm64': 3.0.4 - '@msgpackr-extract/msgpackr-extract-linux-x64': 3.0.4 - '@msgpackr-extract/msgpackr-extract-win32-x64': 3.0.4 + '@msgpackr-extract/msgpackr-extract-darwin-arm64': 3.0.7 + '@msgpackr-extract/msgpackr-extract-darwin-x64': 3.0.7 + '@msgpackr-extract/msgpackr-extract-linux-arm': 3.0.7 + '@msgpackr-extract/msgpackr-extract-linux-arm64': 3.0.7 + '@msgpackr-extract/msgpackr-extract-linux-x64': 3.0.7 + '@msgpackr-extract/msgpackr-extract-win32-x64': 3.0.7 optional: true - msgpackr@2.0.4: + msgpackr@2.1.4: optionalDependencies: - msgpackr-extract: 3.0.4 + msgpackr-extract: 3.0.7 multimatch@6.0.0: dependencies: @@ -13675,6 +13690,8 @@ snapshots: semver@7.8.5: {} + semver@7.8.6: {} + seroval-plugins@1.7.7(seroval@1.7.7): dependencies: seroval: 1.7.7 @@ -13990,6 +14007,8 @@ snapshots: tslib@2.8.1: {} + tslib@2.9.1: {} + tsup@8.5.0(jiti@2.7.0)(postcss@8.5.23)(supports-color@10.2.2)(typescript@5.9.2)(yaml@2.9.0): dependencies: bundle-require: 5.1.0(esbuild@0.25.0)