Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Reloading config disposes of DI sqs client #191

@qljcherry

Description

@qljcherry

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.



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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions