NimaAra / Easy.MessageHub

No need for .NET Events! A thread-safe, high performance & easy to use cross platform implementation of the Event Aggregator Pattern.
MIT License
258 stars 41 forks source link

Sometimes Unsubscribe method hangs #16

Closed GraySerg closed 5 years ago

GraySerg commented 5 years ago

Hi. Sometimes Unsubscribe method hangs, it looks like deadlock. It occures only on production system with high load, i can't reproduce it locally. I have a lot of internal classes that subscribe on start of windows service, and unsubscribe on stop. And on every service stopping random class hands on unsubscribe. My class looks like

    internal abstract class EasyMonitorService: IMonitorService
    {
        readonly protected Easy.MessageHub.MessageHub hub;
        readonly List<System.Guid> subscriptions;
        public bool IsStarted { get; private set; }
        public EasyMonitorService(Easy.MessageHub.MessageHub hub)
        {
            this.hub = hub;
            subscriptions = new List<Guid>(1); 
        }
        public void Start()
        {
            if (!IsStarted)
            {
                subscriptions.AddRange(OnStart());
                IsStarted = true;
            }
        }
        protected abstract IEnumerable<Guid> OnStart();
        public void Stop()
        {
            foreach (var subscribeGuid in subscriptions)
            {
                hub.Unsubscribe(subscribeGuid);
            }
            OnStop();
        }
        protected virtual void OnStop()
        {

        }
    }
NimaAra commented 5 years ago

This library does not utilize multiple threads. All operations are executed on whatever thread your application is doing the publication/subscription on.

Were there any exceptions thrown by the hub? How about any exceptions thrown by the application?

I cannot provide much help without knowing about your application as a whole. I suggest capturing a dump when this happens in production and going through it to see what the thread was doing at the time.

Alternatively you can download the source, add logging to Subscriptions.Unregister and observe the behaviour.

GraySerg commented 5 years ago

No exceptions, just hangs. Start and stop occures in one thread. It's a pity, but impossible to take dump from production server.

NimaAra commented 5 years ago

Try referencing the library directly and adding some logging. I cannot think of anything else.

NimaAra commented 5 years ago

I am closing the issue for now, feel free to re-open it once you have tried my suggestion or have more data we can work with.

ummarbhutta commented 4 years ago

Hi @NimaAra and @GraySerg

I think that I hit a similar issue on one of our test server. The state of application is totally non responsive state, and interestingly all other threads of application stopped as well. Bit details as follows

Environment

Observation

In short, I think what @GraySerg has reported, seems to be a real bug, I think we should try to find the root cause of issue.

@GraySerg , did you find any clue on your side?

NimaAra commented 4 years ago

@ummarbhutta Can you please upgrade to the latest and let me know if this happen again.