-
Notifications
You must be signed in to change notification settings - Fork 112
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
Process started with --test
not killed
#191
Comments
Turns out the server I was running wasn't shutting down because of a bug in I'll close this now. Sorry for the noise! |
Great, thanks for the update! |
I'm running into the same problem. Have a servant server which is forked from the main thread, and it isn't killed on file change. Tested without forking, i.e. running directly from the main thread. The same. Ports and file handles are not released. Running with Instead of Yesod's approach which requires changing/adding some code, a simpler way might be to have an arg to We could put any command in |
Something like (I just glanced the code, so maybe another place) sessionReload :: Session -> IO ([Load], [FilePath])
sessionReload session@Session{..} = do
-- kill anything async, set stuck if you didn't succeed
old <- modifyVar running $ \b -> return (False, b)
-- if killerPath is specified (Just), run it, regardless of `stuck`
void $ createProcess . shell <$> getKillerPathSomehow session
stuck <- if not old then return False else do
Just ghci <- readIORef ghci
fmap isNothing $ timeout 5 $ interrupt ghci
if stuck then sessionRestart session else do
... |
I was using sessionReload :: Session -> IO ([Load], [FilePath])
sessionReload session@Session{..} = do
let killerScript = Just "ghcid-killer-script" -- hardcoded, need access to `Options`
maybe (pure ())
(\ks -> do
(_,_,_,p) <- createProcess $ shell ks
void $ waitForProcess p -- wait for shell process to finish
)
killerScript
... Luckily, I already have the shutdown endpoint in my app, so the only thing needed was the # ghcid-killer-script
curl localhost:3003/admin/stop Any remarks/suggestions on the approach? |
If anybody wants to test, here it is. |
@ndmitchell Any thoughts? |
@vlatkoB sorry for the delay in coming back to you. If you really need such a killer script happy to take a command line flag for something to run and cleanup at some point. However...
|
No problem, not an urgent issue, this one. :-)
This is what I'm using. echo "Killing localhost"
curl -s localhost:3003/admin/stop
sleep 4 |
I imagine you writing:
Which will cause the "test" operation to first call script killer, then |
It doesn't work. Seems those |
I'm using ;; Run 'stop-server' located in project's root on every manual save of Haskell file
(defvar stop-server-script-name "stop-server"
"Name of the script in project root directory." )
(defun stop-dev-server ()
"Kill server so ghcid can reload with server already stopped from outside."
(when (eq major-mode 'haskell-mode) ;; if haskell mode
(when (memq this-command '(save-buffer)) ;; if manual save
(let* ((project-root (projectile-project-root)) ;; curr project root
(script-path (concat project-root stop-server-script-name)) ;; full path
(script-exist (file-exists-p script-path)) ;; does it exist
(shell-cmd (concat script-path " %s"))) ;; make it accept param
(if script-exist
(progn (message "Stopping server with script: %s" script-path)
(shell-command-to-string (format shell-cmd buffer-file-name)))
(message "Missing script %s. No action." script-path))))))
(add-hook 'before-save-hook 'stop-dev-server) I'll try to dig into this issue when I get more free time. |
No idea why |
I remember that, while I was searching/testing for the most appropriate place for the new code, the new code didn't work inside the |
@vlatkoB very odd... I don't understand at all. |
I was in a bit of a hurry to make it done, so I might have missed something. Will test again with a very small/basic Servant app, maybe it's something in the app I used it with. |
I noticed something that might be related to this issue. #!/bin/bash
## script for starting named ghcid session
CMD="ghcid -W -c \"stack ghci server\" -T \":main -c config/config-300$1.yaml\""
bash -c "exec -a "GHCID-RUN" $CMD" get processes info $ ps -o pid,ppid,sess,cmd -U vlatko | grep -v "color" | grep 22825
PID Parent Group CMD
22825 9824 22825 bash
25481 22825 22825 bash
25482 25481 22825 GHCID-RUN -W -c stack ghci server -T :main -c config/config-3005.yaml
25487 25482 22825 .stack/programs/x86_64-linux/ghc-tinfo6-8.6.4/lib/ghc-8.6.4/bin/ghc .... and try to kill them with $ ps -o pid,ppid,sess,cmd -U vlatko | grep -v "color" | grep 22825
PID Parent Group CMD
25487 25482 22825 .stack/programs/x86_64-linux/ghc-tinfo6-8.6.4/lib/ghc-8.6.4/bin/ghc .... The only way to kill it is by being specific about its PID, EDIT: removed |
I'm noticing the same thing with Flora these past days. This is the first time I'm encountering this and I'm quite lost as to why it didn't happen before. I'm don't think I'm particularly stressing ghcid on this one, my command-line is I'm running Fedora 34. |
When using nix shebangs the following works for me to overcome the issue (assuming the executable source file is
|
I'm a Windows user, so don't know what is going on here. If anyone can shed some light, then we can investigate. Reopening for now though, as it does seem there is some issue underlying it. |
Update: turns out an infinite loops from a websocket endpoint was somehow triggering a sequence of events that was leading to this. |
The |
I'm not sure that ghcid detects that a change to a module has happened, loads the new modules and calls the new test. |
My current theory is that https://github.com/ndmitchell/ghcid/blob/master/src/Session.hs#L207 which is supposed to SIGINT doesn't succeed but exits cleanly (otherwise timeout should have triggered). |
I made a reproducer here: https://github.com/domenkozar/ghcid-reload-repro Basically I see this bug happens under two conditions:
@ndmitchell if reloading isn't possible by killing the threads, can we force ghcid to always restart? |
@ndmitchell could we run |
Noting that I also ran into this with a GUI application yesterday. |
I'm trying to use
--test Devel.main
to automatically restart a webserver. On first runs this works, but on subsequent runs starting the webserver often fails because of a port conflict. It turns out the previously started webserver process is still around, and it sticks around even after killingghcid
.Searching a bit for old issues I find some related to this problem. I'm using
ghcid
version 0.7 so I believe I should be have all existing patches.Our current build script is based on
yesod-devel
. It includes the following 'hack':From yesod-bin:
I'm not too familiar with the internals of
ghcid
so this may be way off base, but could the problemyesod-devel
circumvents here be the same plaguingghcid
?The text was updated successfully, but these errors were encountered: