Open OlegKarasik opened 6 years ago
Added more information about what is the current startup life-cycle is.
@rwike77
@OlegKarasik The documentaion is incorrect is is a documentaion issue . As per code, Communication listener is opened first https://github.com/Microsoft/service-fabric-services-and-actors-dotnet/blob/0ee6e7b8e1db55dff8f610f991a46b32237b18c2/src/Microsoft.ServiceFabric.Services/Runtime/StatelessServiceInstanceAdapter.cs#L79
@amanbha Thanks for the confirmation and for source link!
I have update issue to reflect that RunAsync
isn't called and as you underlined listener.OpenAsync
is called first.
~I have update the comment with the shutdown sequence information and blogged the details of stateless service life-cycle in details (leaving a link here to avoid information duplication).~
I have updated the issue with more details about shutdown and abort routines.
Good day,
Description
I am currently working on a library project that provides a simple way to hookup custom handlers on services events. During this work I have discovered that stateless service life-cycle doesn't match the one described in the documentation page (this can be issue in docs or this can be a bug or this can be my bad).
In the documentation there is a statement:
Consider the following example - create a new SF application with ASP.NET Core Stateless Service.
Then in the service code files add a class
WebHostWrapper
that would emulate infinite execution ofICommunicationListener.OpenAsync
method:No use this class to wrap
IWebHost
pre-configured by project template.No ideally if we set a breakpoint in
RunAsync
method then it should be hit because as per documentationICommunicationListener.OpenAsync
andRunAsync
are happening in parallel. But if you would try to execute it thenRunAsync
never gets hit.Update 2018/12/05
I have added more information about shutdown and abort cycles.
In documentation we have:
The real shutdown sequence (see Current state) doesn't involve parallelism. The behavior of current state can be easily reproduced using the gist.
Current state
Startup cycle:
CreateServiceInstanceListeners
is called.OpenAsync
called and awaited.RunAsync
is called.OpenAsync
is called.Note: The runtime waits for
OpenAsync
to finish before marking the replica as readyThis behavior can be easily tested by adding
Thread.Sleep(Timeout.Infinite);
to overrides. Also please note in order to test it using the above code don't forget to commentWebHostWrapper
usage.Shutdown cycle:
CloseAsync
method called and awaited.CancellationToken
passed to Service’sRunAsync
method is canceled.RunAsync
method is awaited.OnCloseAsync
method is called and awaited.Abort cycle:
CancellationToken
passed to Service’sRunAsync
method is canceled. All previously createdICommunicationListener
have theirAbort
method executed. The methods are executed in sequence.Abort
method is executed.