This repository was archived by the owner on Sep 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
Reloading config disposes of DI sqs client #191
Copy link
Copy link
Open
Description
Problem
Whenever the configuration events occur, the reloading config creates a new service and disposes of the original. Coupled with the fact that disposing some services, disposes of their dependencies, regardless of origin, this can result in disposal of the base dependency, needed for the newly created service.
Example:
builder.Services.Configure<SQSSenderOptions>(QueueDefaults.Name, builder.Configuration.GetSection("Queue:Event"));
builder.Services.TryAddAWSService<IAmazonSQS>();
builder.Services.AddSQSSender(QueueDefaults.Name);With this example, the base AmazonSQSClient will be disposed upon the first configuration event received.
| oldSender.Dispose(); |
| SQSClient.Dispose(); |
This can break singleton and scoped queue operations, as it will dispose of the amazon client for that particular scope, and future operations will not function.
Workaround
Do not use the reloading config.
builder.Services.AddSQSSender(QueueDefaults.Name, reloadOnChange: false);Note that this workaround does not account for any cases in which a sender service is disposed of, as it will also result in the disposal of the base amazon client.
Possible solutions
- The library can properly support DI scoping.
- The services should never dispose anything they did not explicitly instantiate themselves, unless they are told to do so.
Metadata
Metadata
Assignees
Labels
No labels