You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At Kubernetes pod shutdown, users see repeated Error while trying to stop daemon agents logs:
System.ObjectDisposedException: The CancellationTokenSource has been disposed.
at System.Threading.CancellationTokenSource.get_Token()
at JasperFx.Events.Daemon.JasperFxAsyncDaemon`3.StopAllAsync()
at JasperFx.Events.Daemon.ProjectionCoordinatorBase.PauseAsync()
Root cause
JasperFxAsyncDaemon.StopAllAsync() begins with await _semaphore.WaitAsync(_cancellation.Token). If Dispose() already ran (_cancellation?.Dispose()), reading .Token throws ObjectDisposedException.
ProjectionCoordinatorBase.StopAsync() calls PauseAsync() then daemon.SafeDispose() on every resolved daemon, but the subclass daemon caches (e.g. Marten's ProjectionCoordinator._daemons) are never cleared. Any second Pause/Stop — double AddAsyncDaemon hosted-service registration, user pause + host stop, Wolverine quiesce + host stop — fans StopAllAsync() out over disposed daemons, and PauseAsync() logs each one at Error level.
Latent second bug: after StopAsync, ResumeAsync and the daemon accessors hand back disposed daemons from the stale cache.
Fix
JasperFxAsyncDaemon: _disposed flag, idempotent Dispose(), StopAllAsync() no-ops when disposed (including the Dispose-races-an-in-flight-stop window).
ProjectionCoordinatorBase.StopAsync: new ClearResolvedDaemons() seam so subclass caches are purged after disposal; ResumeAsync then rebuilds fresh daemons.
Marten/Polecat need to implement the new seam when they bump (Marten side also wants AddAsyncDaemon idempotence — tracked separately on marten#5055).
Upstream report: JasperFx/marten#5055
At Kubernetes pod shutdown, users see repeated
Error while trying to stop daemon agentslogs:Root cause
JasperFxAsyncDaemon.StopAllAsync()begins withawait _semaphore.WaitAsync(_cancellation.Token). IfDispose()already ran (_cancellation?.Dispose()), reading.TokenthrowsObjectDisposedException.ProjectionCoordinatorBase.StopAsync()callsPauseAsync()thendaemon.SafeDispose()on every resolved daemon, but the subclass daemon caches (e.g. Marten'sProjectionCoordinator._daemons) are never cleared. Any second Pause/Stop — doubleAddAsyncDaemonhosted-service registration, user pause + host stop, Wolverine quiesce + host stop — fansStopAllAsync()out over disposed daemons, andPauseAsync()logs each one at Error level.StopAsync,ResumeAsyncand the daemon accessors hand back disposed daemons from the stale cache.Fix
JasperFxAsyncDaemon:_disposedflag, idempotentDispose(),StopAllAsync()no-ops when disposed (including the Dispose-races-an-in-flight-stop window).ProjectionCoordinatorBase.PauseAsync: catchObjectDisposedExceptionand log at Debug — same philosophy as the ProjectionCoordinatorBase.executeAsync: terminate on cancellation / disposed data source instead of re-polling (shutdown drain race) #499/#499: terminate coordinator loop on disposed data source / wrapped cancellation #500 handling inexecuteAsync.ProjectionCoordinatorBase.StopAsync: newClearResolvedDaemons()seam so subclass caches are purged after disposal;ResumeAsyncthen rebuilds fresh daemons.Marten/Polecat need to implement the new seam when they bump (Marten side also wants
AddAsyncDaemonidempotence — tracked separately on marten#5055).