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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket connection refused after sleeping with rdm server left running #15

Closed
gnfisher opened this issue Sep 14, 2022 · 10 comments
Closed

Comments

@gnfisher
Copy link
Contributor

馃憢 Hello! This utility greatly improves the quality of my life, thanks for making it and sharing it!

I've run into a rough edge that I'd thought I'd capture in an issue.

While having a running rdm server in the background, I close my laptop. When I open the laptop again, the rdm server is unreachable.

In a codespace, I'll try to view a PR on github and get the following:

% gh pr view --web
Opening <snip> in your browser.
2022/09/14 14:03:41 Can not send command: could not send command: Post "http://unix///tmprdm.sock": dial unix /tmprdm.sock: connect: no such file or directory

If I check on my host machine (macOS) and try to to stop the running server, I get the following error:

~ % rdm stop
2022/09/14 10:03:50 Can not send command: could not send command: Post "http://unix///var/folders/5n/c1kfd01d4p50ddx07vn0zbl40000gn/T/rdm.sock": dial unix /var/folders/5n/c1kfd01d4p50ddx07vn0zbl40000gn/T/rdm.sock: connect: connection refused
~ % rm -rf /var/folders/5n/c1kfd01d4p50ddx07vn0zbl40000gn/T/rdm.sock
~ % rdm server &
[1] 11953
~ %

My current solution is to rm -rf <path to the socket> and restart the server. It would be great if the server could persist, or if it stopped itself when the machine went into a state where the socket gets "lost" (I know almost nothing about unix sockets or what might be happening).

If you're open to it, I might try to put a PR together in my spare time as a project to start learning go, but I will be very slow to do this 馃暫

@BlakeWilliams
Copy link
Owner

@gnfisher Thanks for the report! Glad you're finding it useful, too.

That's really strange behavior, I haven't run into that yet! I'd happily accept a PR that fixes the broken behavior. I wonder if there are any logs, rdm or otherwise that might help pinpoint what's killing the server, or why it's dying?

Maybe something in cat $(rdm logpath) stands out?

@gnfisher
Copy link
Contributor Author

Thanks, I've checked and the log is empty at the moment. Perhaps my manually removing the socket and restarting rdm server wiped it? Next time it happens I'll check the logs again.

@gnfisher
Copy link
Contributor Author

I've had the issue occur again. The logs are empty.

If I try to stop the server, I do get a log:

2022/09/19 10:54:23 Server could not be started: could not listen to unix socket: listen unix /var/folders/5n/c1kfd01d4p50ddx07vn0zbl40000gn/T/rdm.sock: bind: address already in use

It seems like the rdm loses track of its running instance after sleeping and waking?

@gnfisher
Copy link
Contributor Author

I can reproduce this if I close the terminal I ran rdm server & in. Apparently, this sends a SIGHUP signal to the backgrounded process, and I believe it terminates the rdm process. I am still not sure why I have to manually delete the socket so rdm can recreate it when I open a new terminal and try to stop or start a server again.

If I run nohup rdm server & I can close the terminal, open a new one, and rdm stop etc will work as expected. I'm just going to update my gh-cs bash script to start and stop rdm for me in the short term.

TLDR rdm works fine as it is. Perhaps an upgrade would be to daemonize the process with launchd/systemd? Or alternatively to listen for SIGHUP and shut itself down. If that is interesting, I'd be interested in poking around at how that might be solved.

Thanks again for creating this!

@BlakeWilliams
Copy link
Owner

TLDR rdm works fine as it is. Perhaps an upgrade would be to daemonize the process with launchd/systemd? Or alternatively to listen for SIGHUP and shut itself down. If that is interesting, I'd be interested in poking around at how that might be solved.

I think @brasic mentioned wanting something similar. If we could build a command that would allow rdm to easily inject itself into launchd (maybe homebrew can do this?) I'd be supportive of adding it to the repo/binary.

I had looked into doing something like rdm server -d but daemonizing it seemed to cause pbcopy and pbpaste to stop working, likely due to the "reattach-to-user-namespace" problem tmux used to face. I haven't looked into alternatives, but I would love to be able to daemonize somehow.

@brasic
Copy link
Collaborator

brasic commented Sep 23, 2022

I fear that using launchd might have essentially the same user-namespace problem, but it's worth a shot. I'm interested in taking a crack at this since RDM is something I use every day and not having to nohup it would be nice. (Don't let this stop anyone else from working on this though, it would not be the first thing on my open source backlog 馃槄)

@BlakeWilliams
Copy link
Owner

Coming back to this for a second, we could also handle sighup here: https://github.com/BlakeWilliams/remote-development-manager/blob/main/main.go#L21-L28

I could imagine adding a -d option to server that ignores sighup, but by default respects it and kills the process.

@brasic
Copy link
Collaborator

brasic commented Oct 31, 2022

It can't hurt to add the option to ignore HUP or do it by default but launchctl is working great for me. The PR got a little large so I extracted most of it into a new library that should be pretty easy to reuse: https://github.com/brasic/launchd

I should bring it out of draft pretty soon: #16

@brasic
Copy link
Collaborator

brasic commented Oct 31, 2022

OK, found the time to polish that PR up and it's ready to review. I've been using it for a few weeks and have seen no issues managing rdm with launchd instead of manually nohupping it.

@BlakeWilliams
Copy link
Owner

I think this was fixed via #16, so closing for now

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

3 participants