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

unix domain socket not removed if it exists #6856

Open
jmgurney opened this issue Jan 31, 2020 · 4 comments
Open

unix domain socket not removed if it exists #6856

jmgurney opened this issue Jan 31, 2020 · 4 comments
Labels
help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature topic/rpc-api Issues related to Kubo RPC API at /api/v0

Comments

@jmgurney
Copy link

When using a unix domain socket, config:
"API": [ "/ip4/127.0.0.1/tcp/5001", "/unix/var/db/ipfs-go/socket/api.sock" ],

the first time it starts up, it works fine, but the second time it fails:

Error: serveHTTPApi: manet.Listen(/unix/var/db/ipfs-go/socket/api.sock) failed: listen unix /var/db/ipfs-go/socket/api.sock: bind: address already in use

It is common for programs to either use a lock file, or just simply remove it on start.

I've worked around the issue by removing it in my startup file, but a better solution that is more generic would be nice.

@jmgurney jmgurney added the kind/enhancement A net-new feature or improvement to an existing feature label Jan 31, 2020
@hsanjuan
Copy link
Contributor

I cannot reproduce by stopping ipfs normally. The file stays behind only when -KILLing ipfs.

Would you like to submit a patch to remove the unix socket on boot? Probably affects cmd/ipfs/daemon.go (serveHTTPApi).

@hsanjuan hsanjuan added topic/rpc-api Issues related to Kubo RPC API at /api/v0 help wanted Seeking public contribution on this issue labels Jan 31, 2020
@djdv
Copy link
Contributor

djdv commented Feb 1, 2020

(This snippet might be useful)
https://github.com/djdv/go-ipfs/blob/6f22508188cc19132a08523488cc6d3e4f8047aa/plugin/plugins/filesystem/plugin.go#L127-L153

Edit: I've since modified this, looks like my most recent version is:

// maybeRemoveUnixSockets attempts to remove all Unix domain socket paths in a given multiaddr.
// It returns all errors encountered (wrapped), excluding all "not exist" errors.
func maybeRemoveUnixSockets(ma multiaddr.Multiaddr) (err error) {
	multiaddr.ForEach(ma, func(comp multiaddr.Component) bool {
		if comp.Protocol().Code == multiaddr.P_UNIX {
			localPath := comp.Value()
			if runtime.GOOS == "windows" { // `/C:\path` -> `C:\path`
				localPath = strings.TrimPrefix(localPath, `/`)
			}
			osErr := os.Remove(localPath)
			if osErr != nil && !os.IsNotExist(osErr) {
				err = maybeWrapErr(err, osErr)
			}
		}
		return false
	})
	return
}

@NorseGaud
Copy link

Hey @hsanjuan , what's a safe way to kill ipfs if I'm backgrounding the daemon? -15 doesn't seem to impact the running daemon.

@Stebalien
Copy link
Member

@NorseGaud please ask on https://discuss.ipfs.io.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature topic/rpc-api Issues related to Kubo RPC API at /api/v0
Projects
None yet
Development

No branches or pull requests

5 participants