MQTTnet
MQTTnet copied to clipboard
The server shuts down too slowly.
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:
- .net8 use MQTTnet.AspNetCore 4.3.3.952
- 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(); - Connect to the server using any client or even
telnet 127.0.0.1 1883 - 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.
I am also experiencing this behavior. Any update here? What is the workaround for a graceful shutdown?
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?