Skip to content

Error writing Frame accumulator bytes since 5.27.0 #1778

@markus-raffling-skidata

Description

@markus-raffling-skidata

Describe the bug

With amqp-client java library version 5.27.0 the method writeToByteBuf in class com.rabbitmq.client.impl.Frame has a bug when writing the accumulator bytes in line 218

@Override
public void write(byte[] b) {
	buf.writeBytes(buf);
}

buf.writeBytes(buf);
should be changed to
buf.writeBytes(b);

The effect is that an invalid frame will be sent to the RabbitMQ server, example for channel open:
01 00 01 00 00 00 05 ce
instead of
01 00 01 00 00 00 05 00 14 00 0a 00 ce
and no channels can be opened anymore.

Note for reproduction:

java.io.ByteArrayOutputStream.writeTo(OutputStream) calls either method
write(byte[] b)
or method
write(byte[] b, int off, int len)
depending the current thread is virtual or not

public void writeTo(OutputStream out) throws IOException {
	if (Thread.currentThread().isVirtual()) {
		byte[] bytes;
		synchronized (this) {
			bytes = Arrays.copyOf(buf, count);
		}
		out.write(bytes);
	} else synchronized (this) {
		out.write(buf, 0, count);
	}
}

Reproduction steps

  1. open a RabbitMQ connection with netty config and virtual thread
  2. create a channel

Expected behavior

Channel should be created, accumulator bytes should be sent to RabbitMQ

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions