Skip to content

Encountering "501 FRAME_ERROR" during asynchronous batch publishing #137

@fanmaomao

Description

@fanmaomao

I'm running into a bit of a strange issue when trying to publish messages in batches asynchronously using this library.
I'm consistently getting a "501 FRAME_ERROR" when processing a specific set of messages.

Here's the code I'm using for publishing:

const messages = []; // my datas
const amqp = new AMQPClient(process.env.RabbitMQ_URL);
const connection = await amqp.connect();
const channel = await connection.channel();
const queue = await channel.queue(process.env.RabbitMQ_QUEUE);
await channel.confirmSelect();
await Promise.all(messages.map(message => {
  return queue.publish(
    JSON.stringify(message),
    {
      contentType: 'application/json',
      deliveryMode: 2,
    }
  );
}));

And this is the error output I see:

connection closed by server 501 FRAME_ERROR - type 3, first 16 octets = <<"{\"reqId\":\"4\",\"en">>: {invalid_frame_end_marker,0} 0 0
channel 0 closed: connection closed: FRAME_ERROR - type 3, first 16 octets = <<"{\"reqId\":\"4\",\"en">>: {invalid_frame_end_marker,0} (501)
channel 1 closed: connection closed: FRAME_ERROR - type 3, first 16 octets = <<"{\"reqId\":\"4\",\"en">>: {invalid_frame_end_marker,0} (501)
amqp-client connection closed connection closed: FRAME_ERROR - type 3, first 16 octets = <<"{\"reqId\":\"4\",\"en">>: {invalid_frame_end_marker,0} (501)

Initially, I suspected the issue might be related to the size of the messages, perhaps if they were too large. So, I tried creating a batch with larger messages to test this:

const messages = [
  { cloudfrontReqId: '1', msgId: Buffer.from(crypto.getRandomValues(new Uint8Array(1000))).toString('base64') },
  { cloudfrontReqId: '2', msgId: Buffer.from(crypto.getRandomValues(new Uint8Array(1000))).toString('base64') },
  { cloudfrontReqId: '3', msgId: Buffer.from(crypto.getRandomValues(new Uint8Array(1000))).toString('base64') },
  { cloudfrontReqId: '4', msgId: Buffer.from(crypto.getRandomValues(new Uint8Array(1000))).toString('base64') },
];

Interestingly, with these larger messages, the error did not occur. This made me think it might be something specific about the content of the messages rather than just their size.


Here is the exact batch of data that triggers the "501 FRAME_ERROR":

const messages = [
  {
    reqId: '1',
    entry: {
      entryType: 'resource',
      startTime: 2213551,
      duration: 1745.300000011921,
      initiatorType: 'xmlhttprequest',
      deliveryType: '',
      nextHopProtocol: 'h2',
      renderBlockingStatus: 'non-blocking',
      workerStart: 0,
      redirectStart: 0,
      redirectEnd: 0,
      fetchStart: 2213551,
      domainLookupStart: 2213551,
      domainLookupEnd: 2213551,
      connectStart: 2213551,
      secureConnectionStart: 2213551,
      connectEnd: 2213551,
      requestStart: 2214132.200000018,
      responseStart: 2215295.5,
      firstInterimResponseStart: 0,
      finalResponseHeadersStart: 2215295.5,
      responseEnd: 2215296.300000012,
      transferSize: 384,
      encodedBodySize: 84,
      decodedBodySize: 68,
      responseStatus: 200,
      serverTiming: []
    }
  },
  {
    reqId: '2',
    entry: {
      entryType: 'resource',
      startTime: 2215299.5,
      duration: 167.2000000178814,
      initiatorType: 'xmlhttprequest',
      deliveryType: '',
      nextHopProtocol: 'h2',
      renderBlockingStatus: 'non-blocking',
      workerStart: 0,
      redirectStart: 0,
      redirectEnd: 0,
      fetchStart: 2215299.5,
      domainLookupStart: 2215299.5,
      domainLookupEnd: 2215299.5,
      connectStart: 2215299.5,
      secureConnectionStart: 2215299.5,
      connectEnd: 2215299.5,
      requestStart: 2215374.600000024,
      responseStart: 2215466.100000024,
      firstInterimResponseStart: 0,
      finalResponseHeadersStart: 2215466.100000024,
      responseEnd: 2215466.700000018,
      transferSize: 1822,
      encodedBodySize: 1522,
      decodedBodySize: 4028,
      responseStatus: 200,
      serverTiming: []
    }
  },
  {
    reqId: '3',
    entry: {
      entryType: 'resource',
      startTime: 2215468.700000018,
      duration: 205.7999999821186,
      initiatorType: 'xmlhttprequest',
      deliveryType: '',
      nextHopProtocol: 'h2',
      renderBlockingStatus: 'non-blocking',
      workerStart: 0,
      redirectStart: 0,
      redirectEnd: 0,
      fetchStart: 2215468.700000018,
      domainLookupStart: 2215468.700000018,
      domainLookupEnd: 2215468.700000018,
      connectStart: 2215468.700000018,
      secureConnectionStart: 2215468.700000018,
      connectEnd: 2215468.700000018,
      requestStart: 2215546.800000012,
      responseStart: 2215673.800000012,
      firstInterimResponseStart: 0,
      finalResponseHeadersStart: 2215673.800000012,
      responseEnd: 2215674.5,
      transferSize: 10506,
      encodedBodySize: 10206,
      decodedBodySize: 69146,
      responseStatus: 200,
      serverTiming: []
    }
  },
  {
    reqId: '4',
    entry: {
      entryType: 'resource',
      startTime: 2215970.400000006,
      duration: 501.09999999403954,
      initiatorType: 'xmlhttprequest',
      deliveryType: '',
      nextHopProtocol: 'h2',
      renderBlockingStatus: 'non-blocking',
      workerStart: 0,
      redirectStart: 0,
      redirectEnd: 0,
      fetchStart: 2215970.400000006,
      domainLookupStart: 2215970.400000006,
      domainLookupEnd: 2215970.400000006,
      connectStart: 2215970.400000006,
      secureConnectionStart: 2215970.400000006,
      connectEnd: 2215970.400000006,
      requestStart: 2215970.900000006,
      responseStart: 2216470.600000024,
      firstInterimResponseStart: 0,
      finalResponseHeadersStart: 2216470.600000024,
      responseEnd: 2216471.5,
      transferSize: 384,
      encodedBodySize: 84,
      decodedBodySize: 68,
      responseStatus: 200,
      serverTiming: []
    }
  }
];

This issue is blocking me from reliably publishing this type of data in batches.


Here are the relevant versions:

  • amqp-client: v3.2.1
  • Node.js: v20
  • RabbitMQ: 3.13.7

Any help or pointers on what might be going wrong here would be greatly appreciated!
Thanks so much for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions