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

sftp backend only auto-disconnects sftp subsystem, not ssh connection #103

Closed
funkyshu opened this issue Nov 3, 2021 · 0 comments · Fixed by #104
Closed

sftp backend only auto-disconnects sftp subsystem, not ssh connection #103

funkyshu opened this issue Nov 3, 2021 · 0 comments · Fixed by #104
Assignees
Labels

Comments

@funkyshu
Copy link
Member

funkyshu commented Nov 3, 2021

sftp backend automatically disconnects when no command has been issued in the last 10 seconds (default). However, it appears to only close the SFTP subsystem session, not the underlying SSH connection. This is not a problem when the application closes but is definitely a problem on long-running apps. Memory may eventually run out or ssh service max connections may be reached.

If you run the following test app, the server side (at least on OpenSSH server), every connection will show the main connection sshd: <username> [priv], and two forked processes sshd: <username>@notty and sshd: <username>@internal-sftp. 10 second after each connection was mad the subsytem @internal-sftp process goes away but leaves the other two.

package main

import (
	"fmt"

	"github.com/c2fo/vfs/v6/backend/sftp"
)

func main() {
        // 10 separate connections are made
	for i := 1; i < 11; i++ {
		err := list()
		if err != nil {
			panic(err)
		}
	}
	fmt.Println("DONE")

        // blocking -- ctrl-c when done
	select {}
}

func list() error {

	fs := &sftp.FileSystem{}
	fs = fs.WithOptions(sftp.Options{Password: "mySecretPassword"})
	loc, err := fs.NewLocation("[email protected]", "/home/myusername/")
	if err != nil {
		return err
	}
	fmt.Printf("checking %s\n", loc.URI())

        // connection is made here
	files, err := loc.List()
	if err != nil {
		return err
	}
	fmt.Printf("%v", files)
	return nil
}

Need to close the underlying ssh conn.

@funkyshu funkyshu added the bug label Nov 3, 2021
@funkyshu funkyshu self-assigned this Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant