I discovered a bug related to the queue `contentType` option [1] and dead letter queues [2]. When `c

I discovered a bug related to the queue contentType option [1] and dead letter queues [2].
When contentType is set to anything other than "v8" and the queue event ends up in the DLQ, a consumer worker attached to that DLQ cannot handle it.

// Any contentType other than "v8" cannot be handled in the DLQ
env.MY_QUEUE.send({ foo: "bar" }, { contentType: "json" });

// This is handled fine by the DLQ consumer worker
env.MY_QUEUE.send({ foo: "bar" });
// This is also fine
env.MY_QUEUE.send({ foo: "bar" }, { contentType: "v8" });


The logs of the DLQ consumer worker show for any such non-v8 event:
"Unable to deserialize cloned data due to invalid or unsupported version."


Here's a minimal example of a producer-consumer worker to reproduce the issue:
export interface Env {
    MY_QUEUE: Queue;
}

export default {
    async fetch(req: Request, env: Env): Promise<Response> {
        // Any contentType other than "v8" cannot be handled in the DLQ
        await env.MY_QUEUE.send({ foo: 'bar' }, { contentType: 'json' });
        return new Response('Sent message to the queue');
    },

    async queue(batch: MessageBatch<Error>, env: Env): Promise<void> {
        // Due to this error, the event will end up in the dead letter queue
        throw new Error('Foobar');
    },
};


And a minimal DLQ consumer:
export default {
    async queue(batch: MessageBatch<Error>, env: Env): Promise<void> {
        console.log(`Events received: ${JSON.stringify(batch.messages)}`);
    },
};


Relevant docs:
[1] https://developers.cloudflare.com/queues/platform/javascript-apis/#queuescontenttype
[2] https://developers.cloudflare.com/queues/learning/batching-retries/#dead-letter-queues
Was this page helpful?