Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle disconnect -> close properly in ChoosePartions #225

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed race condition in `Producer` between `Send(...)` and `DisposeAsync()` dispose causing an unintended
`DivideByZeroException`. It now correctly throws a `ProducerClosedException`

## [3.3.0] - 2024-06-10

### Added
Expand Down
5 changes: 4 additions & 1 deletion src/DotPulsar/Internal/Producer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private SubProducer CreateSubProducer(string topic, int partition)
process.Start();
return producer;
}

public bool IsFinalState()
=> _state.IsFinalState();

Expand Down Expand Up @@ -202,9 +203,11 @@ private async ValueTask<int> ChoosePartitions(MessageMetadata metadata, Cancella
{
if (_producerCount == 0)
{
_ = await _state.StateChangedFrom(ProducerState.Disconnected, cancellationToken).ConfigureAwait(false);
var newState = await _state.StateChangedFrom(ProducerState.Disconnected, cancellationToken).ConfigureAwait(false);
if (_faultException is not null)
throw new ProducerFaultedException(_faultException);
if (newState == ProducerState.Closed)
throw new ProducerClosedException();
}

if (_producerCount == 1)
Expand Down
Loading