kerryjiang / SuperSocket

SuperSocket is a light weight, cross platform and extensible socket server application framework.
Apache License 2.0
3.95k stars 1.15k forks source link

Clear Idle Session #675

Closed alberk8 closed 1 year ago

alberk8 commented 1 year ago

I am have a console app that works but it seems that supersocket is not clearing Idle Session. I test by connect client to it and It is connection is established then I pull out the network cable to simulate connection error/timeout. I waited for 10-30 minutes and there is no timeout and subsequent connecting to it increase the session count. Is there any setting I need to set to get the clear idle session to work. I am on the latest V2.0beta-17 with Net7 on Windows.

var host = SuperSocketHostBuilder.Create<StringPackageInfo, LinePipelineFilter>(args)
       .UseSession<MyUseSession>()
           .ConfigureServices((context, service) =>
             {
                 // Hosting SingleTon
             }
           .Build();

await host.RunAsync();

public class MyUseSession : AppSession
    {

        protected override async ValueTask OnSessionConnectedAsync()
        {
            Console.WriteLine($"Name: {this.Server.Options.Name} ClearIdleInterval: {this.Server.Options.ClearIdleSessionInterval}" +
                $" IdleSessionTimeout: {this.Server.Options.IdleSessionTimeOut}");
            Console.WriteLine("Session Count:" + this.Server.SessionCount);
            Console.WriteLine("RemoteIP: " + this.Channel.RemoteEndPoint.ToString());
            await base.OnSessionConnectedAsync();

        }
        protected override void Reset()
        {
            Console.WriteLine("xxxxxxx Connection Reset");
            base.Reset();
        }

        protected override ValueTask OnSessionClosedAsync(CloseEventArgs e)
        {
            Console.WriteLine("xxxxxxx Connection Closed");
            return base.OnSessionClosedAsync(e);
        }
    }
alberk8 commented 1 year ago

I added the UseClearIdleSession() and get a runtime error.

var host = SuperSocketHostBuilder.Create<StringPackageInfo, LinePipelineFilter>(args)
           .UseClearIdleSession()
       .UseSession<MyUseSession>()
           .ConfigureServices((context, service) =>
             {
                 // Hosting SingleTon
             }
           .Build();

System.Exception: 'ClearIdleSessionMiddleware needs a middleware of ISessionContainer'

wj8400684 commented 1 year ago

.UseInProcSessionContainer()

alberk8 commented 1 year ago

.UseInProcSessionContainer()

@wj8400684 That is not available when I tried it.

alberk8 commented 1 year ago

I need to add the nuget Supersocket.SessionContainer for it to work. One more thing is that the UseInProcSessionContainer() must be the last of the .Use .. in the fluent code.