-
Notifications
You must be signed in to change notification settings - Fork 326
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
Properly handle SIGHUP and SIGTERM #305
Conversation
@Provessor Thanks for working on this. Messages sent to the quit channel are sometimes ignored (i.e. when a copy/move operation is in progress). Have you tested this patch to see what happens in this case? Also do you need all three signals or SIGHUP/SIGTERM is enough for #292 and #300 ? Interrupt signal should ideally be handled as part of #162 . It would be great if you're willing to work on this but if not maybe we should simply exclude that signal from this patch. |
@gokcehan If SIGINT is going to be handled more specifically elsewhere I'll remove it from this. As of the last commit, quitChan will not halt the exit if a copy/move/delete operation is in progress on SIGHUP/SIGTERM. I have read through the copy/move/delete code and couldn't see anything from there that needed explicit handling. |
@Provessor You removed I'm not sure if it's a good idea to cancel the copy/move operation altogether. It may be better to keep the operation going in the background. Do you know what is happening to copy/move operations when you close the terminal with the current code? |
@gokcehan my mistake leaving In go the main goroutine must be running for any other goroutines to run. This means when My thought process was if the operation continued after the terminal is disconnected then that could lead to unexpected results, a directory which is being duplicated without an obvious source. Personally I don't think continuing the operation in the background should be the default behaviour, however it's up to you. |
@Provessor So I have tried the current code and it seems that copying is finished when the terminal is closed. For now, I think I agree it is better to finish the copying operation and leave background copying to a future possible server implementation as you suggest. The way goroutines are handled in the patch still feels strange though. Do we want to maintain a separate list of cleanup operations in here? If you agree as well, maybe we should just try to quit, by sending a quit signal as in your first patch, and leave copy case handling as before, by leaving a log file behind. I don't think we will have complaints in the related issues as it will handle the common use case properly and the other case is mostly unintentional. |
@gokcehan I have done some more testing and it seems that there is a gap between window close and copy stopping (at least on my machine) however this is only noticeable with large files (~1G+). I've since changed my mind on this since my last comment; IMHO the best solution to this would be to perform all copy/move/delete operations on a server process (which could then also take over preview caching, etc.) and I would be happy to leave a zombie process to finish these operations with this PR with intentions to pick up on it later. |
@gokcehan it's not possible to daemonize a process in Go (see this or this), I've found one cross-platform package godaemon that uses It is possible to start a new process in the background in pure Go (something like this) so maybe this should be left for a server process implementation? |
@Provessor Yes I think it is better to leave it for a later patch. I'm merging this as it is now. Thanks for the patch. |
Properly handle exit signals SIGHUP and SIGTERM to avoid exiting prematurely.
Fixes #300, #292
To preserve system independence, according to the documentation, when Windows sends CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT or CTRL_SHUTDOWN_EVENT, Notify will return SIGTERM like a *nix system.