Repository navigation
Description
Problem
A late rejection response can reach InsideRuntimeClient.ReceiveResponse after the silo's service provider has been disposed. The response path lazily resolves GrainLocator, causing ObjectDisposedException. This appeared in two of the three audited main runs.
Observed in builds 3025499 and 3026528:
Error creating activation for grain sys.svc.dir.grain.part/... .
Message Unrecoverable Rejection
(info: Message was queued for sending after outbound queue was stopped)
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
at Microsoft.Extensions.DependencyInjection...GetRequiredService(...)
at Orleans.Runtime.InsideRuntimeClient.get_GrainLocator()
in src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 116
at Orleans.Runtime.InsideRuntimeClient.ReceiveResponse(Message message)
in src/Orleans.Runtime/Core/InsideRuntimeClient.cs:line 419
at Orleans.Runtime.Messaging.MessageCenter.ReceiveMessage(Message msg)
in src/Orleans.Runtime/Messaging/MessageCenter.cs:line 526
Relevant code
InsideRuntimeClient lazily resolves runtime services:
private GrainLocator GrainLocator
=> this.grainLocator ?? (this.grainLocator = this.ServiceProvider.GetRequiredService<GrainLocator>());For an unrecoverable/transient rejection, ReceiveResponse invalidates the directory cache before completing the callback:
if (message.CacheInvalidationHeader is null)
{
this.GrainLocator.InvalidateCache(message.SendingGrain);
}MessageCenter.ReceiveMessage continues routing response messages through catalog.RuntimeClient.ReceiveResponse(msg). During stop, InsideRuntimeClient.OnRuntimeInitializeStop disposes the callback timer, waits using the lifecycle cancellation token, and only then breaks outstanding messages.
The latest run also logged an InsideRuntimeClient lifecycle stop cancellation after a 30-second silo shutdown delay, indicating ordering around late responses and runtime disposal needs review.
Expected fix
- Establish a terminal runtime-client state before dependent services are disposed.
- Prevent late responses/rejections from resolving services after that point; complete/fault callbacks without touching disposed DI services.
- Avoid broad exception swallowing: preserve diagnostics for genuinely invalid responses received while the runtime is active.
- Add a shutdown race test which queues an unrecoverable rejection, stops the outbound queue/silo, and asserts no
IServiceProviderdisposal error or lifecycle stop failure.
Activity