WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

AddDaprWorkflow causing singletons to be created multiple times #1567

@ante-maric

Description

@ante-maric

Expected Behavior

IServiceCollection.BuildServiceProvider() should never ever be called from application code because it can result in more than one copy of singleton services being created.

Actual Behavior

Adding AddDaprWorkflow call while using Serilog bootstrap logger will throw exception because singleton logger gets created twice:

System.InvalidOperationException: The logger is already frozen.
at Serilog.Extensions.Hosting.ReloadableLogger.Freeze()
at Serilog.SerilogServiceCollectionExtensions.<>c__DisplayClass3_0.b__0(IServiceProvider services)

Freeze method is called only in singleton factory method.

Thrown exception suggests singleton factory method has been called twice.

This is just one symptom that I ran into, but this can cause other issues depending on what singletons an application is using.

Steps to Reproduce the Problem

  1. Create new ASP.NET Core Web API project
  2. Add Serilog nugets
  3. Add Dapr.Workflow nuget
  4. In Program.Main create bootstrap logger
    Log.Logger = new LoggerConfiguration()
    .WriteTo.Console()
    .CreateBootstrapLogger();
  5. Add dapr workflows: builder.Services.AddDaprWorkflow(x => { });
  6. Run the app and observe InvalidOperationException being thrown preventing startup

Root cause can be found here.

Call to BuildServiceProvider() produces warning that someone choose to ignore.

Release Note

RELEASE NOTE:

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions