Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The server shuts down too slowly. #1916

Open
voids opened this issue Jan 27, 2024 · 2 comments
Open

The server shuts down too slowly. #1916

voids opened this issue Jan 27, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@voids
Copy link

voids commented Jan 27, 2024

Describe the bug

If there is a connection, shutting down the server will be stuck for 30 seconds.

Which component is your bug related to?

  • Server

To Reproduce

Steps to reproduce the behavior:

  1. .net8 use MQTTnet.AspNetCore 4.3.3.952
  2. Run this code below:
    using MQTTnet.AspNetCore;
    using MQTTnet.Server;
    
    var builder = WebApplication.CreateSlimBuilder(args);
    builder.WebHost.UseKestrel(x => {
        x.ListenLocalhost(1883, l => l.UseMqtt());
        x.ListenAnyIP(5001);
    });
    builder.Services.AddConnections();
    builder.Services.AddMqttConnectionHandler();
    builder.Services.AddHostedMqttServer(x => {
        x.WithDefaultEndpoint();
        x.WithPersistentSessions(false);
    });
    var app = builder.Build();
    // Uncomment the code below, it will shut down quickly.
    // app.Lifetime.ApplicationStopping.Register(() => {
    //     app.Services.GetRequiredService<MqttServer>().StopAsync();
    // });
    app.Run();
  3. Connect to the server using any client or even telnet 127.0.0.1 1883
  4. Return to server terminal, ctrl+c , it will shut down after about 30 senconds.

Expected behavior

I'm not sure if it's intentional, but I hope it shuts down gracefully asap.

@voids voids added the bug Something isn't working label Jan 27, 2024
@kimhegg
Copy link

kimhegg commented Feb 21, 2024

I am also experiencing this behavior. Any update here? What is the workaround for a graceful shutdown?

@chkr1011
Copy link
Collaborator

chkr1011 commented Mar 2, 2024

This seems to be related to ASP since a server shutdown is pretty fast when using the code from the samples app.

Could you please try without port 5001 and let me know if there is any difference in behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants