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

Cant stop the Server #143

Open
Crashdummyy opened this issue Sep 19, 2022 · 2 comments
Open

Cant stop the Server #143

Crashdummyy opened this issue Sep 19, 2022 · 2 comments

Comments

@Crashdummyy
Copy link

Crashdummyy commented Sep 19, 2022

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 ?

@fubar-coder
Copy link
Contributor

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.

@Crashdummyy
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants