Search code examples
haskellyesod

yesod devel does not rebuild when pressing enter and does not shut down properly


I'm having a few issues with Yesod's development server after following the Yesod Quick start guide:

  • The development server does not respond to typed commands or pressing enter to trigger a rebuild. When I type commands, I can see that the text is being inputted (the words are displayed in the terminal), but the development server does not respond to them.
  • If I restart Yesod multiple times, it'll eventually crash on start saying that the development port needed for TLS is not available. I suspect that this means that there are processes from older runs still hanging around.
  • New static files aren't served even after a restart. I suspect that this might also relate to old processes hanging around, since I'm not sure how my static files would be persisting across rebuilds otherwise (I've also been rerunning with stack clean && stack build && stack exec -- yesod devel)

EDIT In addition to the accepted answer, my static files weren't reloading because Yesod apparently serves static files with a Cache-Control header even in local development. So, doing a hard refresh got them loading in the browser.


Solution

  • Your first issue appears to be a long-standing yesod-bin bug. Commit b3ed4613 puts the stack build --file-watch process in its own process group which then gets stopped by job control when it tries to read user commands from standard input. The commit is 5 years old; no idea why it hasn't been reported before now.

    I filed issue #1860 that explains the problem and offers a suggested solution.

    In the meantime, you can build and install your own yesod-bin package with the following patch which seems to fix the problem for me.

    diff --git a/Devel.hs b/Devel.hs
    index a871463..325416b 100644
    --- a/Devel.hs
    +++ b/Devel.hs
    @@ -351,7 +351,6 @@ devel opts passThroughArgs = do
             myPath <- getExecutablePath
             let procConfig = setStdout createSource
                            $ setStderr createSource
    -                       $ setCreateGroup True -- because need when yesod-bin killed and kill child ghc
                            $ proc "stack" $
                     [ "build"
                     , "--fast"
    

    Hopefully, as you suspect, your other issues are related to this first issue.