Skip to content

Transactional publishes do not set txn id in MessageMetadata #1498

Description

@jiangmocc

Bug description

Transactional publishes currently put the transaction id on CommandSend, but the serialized MessageMetadata does not carry txnid_most_bits and txnid_least_bits for producer-created messages.

Because the broker-side transaction buffer uses the transaction id in message metadata to identify transactional entries, messages published inside a transaction can be treated as normal visible messages. In particular, after aborting the transaction, those messages may still be delivered to consumers.

Expected behavior

Messages published with ProducerMessage.Transaction should include the transaction id in MessageMetadata as well as in CommandSend, so aborted transaction messages remain invisible and are removed by the transaction buffer.

Actual behavior

The producer resolves the transaction id for send commands, but does not copy it into MessageMetadata for single-message sends or batch metadata.

Suggested fix

When a send request has a transaction:

  • set MessageMetadata.TxnidMostBits and MessageMetadata.TxnidLeastBits for single-message sends
  • set the same fields on batch-level MessageMetadata when the first message in a batch is transactional
  • clear the batch transaction fields after flushing so a later non-transactional batch cannot inherit them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions