fs2-rabbit icon indicating copy to clipboard operation
fs2-rabbit copied to clipboard

Handle `prefetchCount` > max Short value

Open Daenyth opened this issue 5 years ago • 3 comments

The AMQP spec says that prefetchCount is a short (16-bit) value. Despite this, the java amqp-client accents an int parameter. The int then has its MSB stripped off, and the remainder is reinterpreted as a short.

For example, if you supply a prefetch of 1_000_000, that gets interpreted as a prefetchCount of 16960

0b11110100001001000000 // 1_000_000
-----0b100001001000000 // 16_960

I have two proposals:

  • ~~fs2-rabbit can change its own prefetchCount parameter of BasicQos to be a Short instead of an Int. Then invalid values simply can't be passed. Comments can direct the user about what to do~~ It's actually interpreted as an unsigned short, so we don't have an out of the box type for it.
  • (binary compatible) fs2-rabbit can log an error when there's an attempt to basicConsume with prefetchCount > (2^16-1). We can also optionally "round" the requested count down to exactly (2^16-1)

Daenyth avatar Mar 31 '20 14:03 Daenyth

I've opened an issue upstream as well: https://github.com/rabbitmq/rabbitmq-java-client/issues/640

drobert avatar Mar 31 '20 19:03 drobert

Following up, it seems the technical limit is a logical "unsigned short" (see https://github.com/rabbitmq/rabbitmq-java-client/issues/640#issuecomment-606891124 ). So @Daenyth is correct with 2^16, or 65535

drobert avatar Mar 31 '20 21:03 drobert

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 30 '20 09:07 stale[bot]