You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "eugene-polozhenkov (via GitHub)" <gi...@apache.org> on 2026/08/10 17:47:53 UTC

[PR] Fix race conditions in ConnectionPool and SubProducer causing ThreadPool starvation [pulsar-dotpulsar]

eugene-polozhenkov opened a new pull request, #292:
URL: https://github.com/apache/pulsar-dotpulsar/pull/292

   Fixes #{291}
   
   ## Changes
   
   ### `SubProducer.EstablishNewChannel`
   The `Task.Run` lambda captured `_dispatcherCts` and `_channel` fields rather than local values. Under thread pool saturation a concurrent `EstablishNewChannel` call could dispose `_dispatcherCts` before the lambda read `.Token`, causing `ObjectDisposedException` -> fatal producer fault -> recreation death spiral.
   
   Fix: materialize `token = cts.Token` and pin `channel` to locals before `Task.Run`.
   
   ### `ConnectionPool.GetConnection`
   No serialization on connection establishment: all N producers missing the cache simultaneously called `EstablishNewConnection` in parallel, spawning N(producers) TCP connections and background tasks.
   
   Fix: `SemaphoreSlim(1,1)` gate per `PulsarUrl` with double-checked locking.
   
   ### `ConnectionPool.DisposeConnection`
   `TryRemove(key)` removed whichever connection was at the key, not specifically the dead one. Under load the `ContinueWith` delay could cause it to evict a freshly established replacement.
   
   Fix: `TryRemove(KeyValuePair<K,V>)` / `ICollection.Remove(kvp)` for atomic
   key+value comparison, with `#if NETSTANDARD2_0 || NETSTANDARD2_1` following the existing library pattern.
   
   ## Tests
   - `SubProducerTests`: unit test for the dispatcher field-capture race
   - `ConnectionPoolTests`: integration tests verifying all producers share a single
     connection after simultaneous reconnect (asserted via broker admin stats)
   - `IntegrationFixture`: `CreateAdminClient()` moved here from `ConsumerTests`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix race conditions in ConnectionPool and SubProducer causing ThreadPool starvation [pulsar-dotpulsar]

Posted by "blankensteiner (via GitHub)" <gi...@apache.org>.
blankensteiner commented on PR #292:
URL: https://github.com/apache/pulsar-dotpulsar/pull/292#issuecomment-5250810892

   Very nice, thanks! :-)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix race conditions in ConnectionPool and SubProducer causing ThreadPool starvation [pulsar-dotpulsar]

Posted by "blankensteiner (via GitHub)" <gi...@apache.org>.
blankensteiner merged PR #292:
URL: https://github.com/apache/pulsar-dotpulsar/pull/292


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org