Skip to content

Commit

Permalink
txn: document that canceling contexts is not recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
twmb committed Mar 29, 2021
1 parent bef2311 commit c8cd120
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/kgo/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ func (s *GroupTransactSession) Begin() error {
// in committing offsets fails, this aborts.
//
// This returns whether the transaction committed or any error that occurred.
//
// Note that canceling the context will likely leave the client in an
// undesirable state, because canceling the context cancels in flight requests
// and prevents new requests (multiple requests are issued at the end of a
// transact session). Thus, while a context is allowed, it is strongly
// recommended to not cancel it.
func (s *GroupTransactSession) End(ctx context.Context, commit TransactionEndTry) (bool, error) {
defer func() {
s.revokeMu.Lock()
Expand Down Expand Up @@ -315,6 +321,11 @@ func (cl *Client) AbortBufferedRecords(ctx context.Context) error {
// If records failed with UnknownProducerID and your Kafka version is at least
// 2.5.0, then aborting here will potentially allow the client to recover for
// more production.
//
// Note that canceling the context will likely leave the client in an
// undesirable state, because canceling the context may cancel the in-flight
// EndTransaction request, making it impossible to know whether the commit or
// abort was successful. It is recommended to not cancel the context.
func (cl *Client) EndTransaction(ctx context.Context, commit TransactionEndTry) error {
cl.producer.txnMu.Lock()
defer cl.producer.txnMu.Unlock()
Expand Down

0 comments on commit c8cd120

Please sign in to comment.