NET5 Kestrel issue keeping connection id alive on load balanced servers

Colunga, Daniel 1 Reputation point
2021-09-01T21:19:19.013+00:00

Hi!

I have a simple self-hosted REST API NET5 service and when I deploy it on the load balanced servers I see this in the logs (and it repeats every almost second)

DEBUG 2021-09-01 13:56:14,473 [4] Sockets - Connection id "0HMBDE70O3LAT" received FIN.
DEBUG 2021-09-01 13:56:14,474 [4] Kestrel - Connection id "0HMBDE70O3LAT" accepted.
DEBUG 2021-09-01 13:56:14,474 [9] Kestrel - Connection id "0HMBDE70O3LAT" started.
DEBUG 2021-09-01 13:56:14,474 [9] Sockets - Connection id "0HMBDE70O3LAT" sending FIN because: "The client closed the connection."
DEBUG 2021-09-01 13:56:14,475 [9] Kestrel - Connection id "0HMBDE70O3LAT" disconnecting.
DEBUG 2021-09-01 13:56:14,475 [9] Kestrel - Connection id "0HMBDE70O3LAT" stopped.
DEBUG 2021-09-01 13:56:15,137 [4] Sockets - Connection id "0HMBDE70O3LAU" received FIN.
DEBUG 2021-09-01 13:56:15,137 [4] Kestrel - Connection id "0HMBDE70O3LAU" accepted.
DEBUG 2021-09-01 13:56:15,138 [5] Kestrel - Connection id "0HMBDE70O3LAU" started.
DEBUG 2021-09-01 13:56:15,138 [5] Sockets - Connection id "0HMBDE70O3LAU" sending FIN because: "The client closed the connection."
DEBUG 2021-09-01 13:56:15,138 [5] Kestrel - Connection id "0HMBDE70O3LAU" disconnecting.
DEBUG 2021-09-01 13:56:15,138 [5] Kestrel - Connection id "0HMBDE70O3LAU" stopped.
DEBUG 2021-09-01 13:56:19,473 [4] Sockets - Connection id "0HMBDE70O3LAV" received FIN.
DEBUG 2021-09-01 13:56:19,473 [4] Kestrel - Connection id "0HMBDE70O3LAV" accepted.
DEBUG 2021-09-01 13:56:19,474 [5] Kestrel - Connection id "0HMBDE70O3LAV" started.
DEBUG 2021-09-01 13:56:19,474 [5] Sockets - Connection id "0HMBDE70O3LAV" sending FIN because: "The client closed the connection."
DEBUG 2021-09-01 13:56:19,474 [5] Kestrel - Connection id "0HMBDE70O3LAV" disconnecting.
DEBUG 2021-09-01 13:56:19,474 [5] Kestrel - Connection id "0HMBDE70O3LAV" stopped.
DEBUG 2021-09-01 13:56:20,169 [4] Sockets - Connection id "0HMBDE70O3LB0" received FIN.
DEBUG 2021-09-01 13:56:20,169 [4] Kestrel - Connection id "0HMBDE70O3LB0" accepted.
DEBUG 2021-09-01 13:56:20,169 [13] Kestrel - Connection id "0HMBDE70O3LB0" started.
DEBUG 2021-09-01 13:56:20,169 [13] Sockets - Connection id "0HMBDE70O3LB0" sending FIN because: "The client closed the connection."
DEBUG 2021-09-01 13:56:20,170 [13] Kestrel - Connection id "0HMBDE70O3LB0" disconnecting.
DEBUG 2021-09-01 13:56:20,170 [13] Kestrel - Connection id "0HMBDE70O3LB0" stopped.

This doesn't happen on the local machine and on a clustered server. Any idea what it can be and how to solve it?

Thanks, regards!

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,339 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,701 Reputation points
    2021-09-06T08:37:12.337+00:00

    Hello,

    Thank you for your question.

    Can you check KeepAlive and Timeout values on your both load balanced servers and make sure both are same.

    Also can you try after move out one by one member server from load balanced servers pool.

    If the reply was helpful, please don’t forget to upvote or accept as answer.

    0 comments No comments

  2. Colunga, Daniel 1 Reputation point
    2021-09-07T20:54:07.727+00:00

    Hi!

    Yes, timeout and keepalive are the same.

    I also tried to move out one and the issue keeps the same.

    The weird thing is when I start the service it starts to log this connection/disconnection loop, and I'm not making any calls to the API (not sure what is the relation of this connections). If I try to call a test method, a http connection is created and this connection is keeping alive until the default value (that is 2 minutes) and this is ok.

    This is the Configure and ConfigureServices method:

    public void ConfigureServices(IServiceCollection services)
    {
    services.AddControllers();
    services.AddMvc().AddNewtonsoftJson(options =>
    {
    options.SerializerSettings.ContractResolver = new DefaultContractResolver();
    });
    }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddLog4Net();
    
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
    
            app.UseRouting();
            app.UseCors(x => x.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    

    And this is the Program class:

    class Program
    {
    public static IConfiguration Configuration { get; set; }

        static void Main(string[] args)
        {
            Configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build();
            var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
            var pathToContentRoot = Path.GetDirectoryName(pathToExe);
            var host = CreateHostBuilder(args, pathToContentRoot);
            host.Build().Run();
        }
    
        public static IHostBuilder CreateHostBuilder(string[] args, string pathToContentRoot) =>
            Host.CreateDefaultBuilder(args)
                .UseSystemd()
                .UseWindowsService()
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseContentRoot(pathToContentRoot)
                              .UseConfiguration(Configuration)
                              .UseStartup<Startup>();
                });
    }
    

    Any other idea?

    Thanks, regards!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.