Heartbeat works but only if Notify is called

Hey Demis,

It’s unclear from documentation/ method API (& [lack of :smile:] comments), that the heartbeat keep alive only functions as expected if notify is called (which includes code to clear stale subscriptions).

I would suggest making this a bit clearer.


Not sure what you mean by not functioning as expected?

Heartbeat is a keep alive, if not received within a certain time frame e.g. every 10 seconds, subscriptions are supposed to go stale, I would have expected stale subscriptions to be removed automatically.

There is no background thread/ timer that automatically removes stale subscriptions.

IServerEvents gives no information on most recent heartbeat per subscription, because it just returns SubscriptionInfo objects, which don’t have a LastPulse property. This indicated to me that idle subscriptions should be automatically taken care of. But it’s not automatically taken care of, the only way MemoryServerEvents will remove stale/ idle subscriptions, is when

    protected void Notify(ConcurrentDictionary<string, IEventSubscription[]> map, string key,
        string selector, object message, string channel = null)

is called.

Maybe you assumed Notify will be called regularly in the use cases you envisioned, therefore you didn’t have to make MemoryServerEvents explicitly check every so often for stale connections?

1 Like

Right, by design it doesn’t have a background thread to periodically clean up stale connections and relies on SSE notifications to handle clean up. I’ll look at expanding this to also perform clean ups during regular heartbeat intervals to mitigate SSE connections with low activity.

I have the same problem. Any time-frame on when this might get fixed?

There’s now a ServerEventsFeature.HouseKeepingInterval option to throttle the min time for expired subscriptions to be removed in this commit. This is used in RemoveExpiredSubscriptions() to throttle scanning of expired subscriptions which is called on each heatbeat.

This change is available from v4.0.43+ that’s now available on MyGet.