FtpServer icon indicating copy to clipboard operation
FtpServer copied to clipboard

Cant stop the Server

Open Crashdummyy opened this issue 3 years ago • 2 comments

Hi there

I use this server in an asp.net core webai where I just start it when I need to obtain a specific directory.

    public Task StartServerForBasedir(string baseDir,
                                      CancellationToken cancellationToken = default)
    {
        var ioc = new ServiceCollection();

        ioc.Configure<DotNetFileSystemOptions>(options => options.RootPath = baseDir);
        
        ioc.AddFtpServer(server => server.UseDotNetFileSystem().UseSingleRoot())
           .AddSingleton<IMembershipProvider, BuddyFtpProvider>();

        ioc.Configure<FtpServerOptions>(options => options.Port = ClassKey.Ports.FTP);

        serviceProvider = ioc.BuildServiceProvider();

        ftpService = serviceProvider.GetRequiredService<IFtpServerHost>();
        return ftpService.StartAsync(cancellationToken);
    }

    public async Task StopServer(CancellationToken cancellationToken = default)
    {
        if (ftpService is null)
            return;
        
        await ftpService.StopAsync(cancellationToken);
        ftpService = null;
        serviceProvider?.DisposeAsync();
    }

Sometimes when I call StopAsync the server refuses to stop.

System.Net.Sockets.SocketException (10048): Only one usage of each socket address (protocol/network address/port) is normally permitted.
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.Net.Sockets.TcpListener.Start(Int32 backlog)
   at FubarDev.FtpServer.MultiBindingTcpListener.StartListening(IEnumerable`1 addresses, Int32 port)
   at FubarDev.FtpServer.MultiBindingTcpListener.StartAsync()
   at FubarDev.FtpServer.Networking.FtpServerListenerService.ExecuteAsync(CancellationToken cancellationToken)
   at FubarDev.FtpServer.Networking.PausableFtpService.RunAsync(IProgress`1 statusProgress)
   at System.Threading.Channels.AsyncOperation`1.GetResult(Int16 token)
   at FubarDev.FtpServer.FtpServer.ReadClientsAsync(ChannelReader`1 tcpClientReader, CancellationToken cancellationToken)
   at FubarDev.FtpServer.FtpServer.StopAsync(CancellationToken cancellationToken)
   at FubarDev.FtpServer.FtpServerHost.StopAsync(CancellationToken cancellationToken)

Frequent calls with delay dont work either :/

Any idea what the hell is wrong up there ?

Crashdummyy avatar Sep 19 '22 13:09 Crashdummyy

It seems that the internal FTP server task fails to start on all specified addresses and you see the shown error message when try to stop it. It would be interesting to see the IP addresses it tries to listen on.

fubar-coder avatar Sep 21 '22 05:09 fubar-coder

It seems that the internal FTP server task fails to start on all specified addresses and you see the shown error message when try to stop it. It would be interesting to see the IP addresses it tries to listen on.

No the Server starts as expected. This exception is sometimes thrown when I try to stop it

Crashdummyy avatar Sep 21 '22 11:09 Crashdummyy