nats-io / stan.net

The official NATS .NET C# Streaming Client
Apache License 2.0
138 stars 41 forks source link

Resolve deadlock when publishing small messages rapidly #175 #177

Closed watfordgnf closed 4 years ago

watfordgnf commented 4 years ago

This resolves deadlocks seen when publishing small messages rapidly as detailed in #175.

The primary resolution is to not hold addLock while also holding dLock within BlockingDictionary.Remove (3d19c4b).

A second observation is that pubAckMap can be made readonly, removing the need for an additional lock wrapping pubAckMap.Remove when processing acks (384fb15).

The last fix is to avoid deadlocks when the connection is lost unexpectedly, seen when interleaving very rapid publishing and publishing slowed with random intervals, by only waiting up to the ping interval before retrying (6d7cdb2).

ColinSullivan1 commented 4 years ago

Overall, LGTM other than the discard question. Feedback on #175 would be great before merging.

watfordgnf commented 4 years ago

I'm unable to reproduce the failing test locally: BasicTests.TestPubMultiQueueSubWithSlowSubscriber either has an unknown subscription or a duplicate message (unable to tell from the failure).