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

cabal repl gets killed by interrupts #1448

Closed
ibotty opened this issue Aug 30, 2013 · 13 comments · Fixed by #1535
Closed

cabal repl gets killed by interrupts #1448

ibotty opened this issue Aug 30, 2013 · 13 comments · Fixed by #1535

Comments

@ibotty
Copy link

ibotty commented Aug 30, 2013

i often use ctrl-c to reset the line i was in in ghci. unfortunately that kills cabal repl.

@23Skidoo
Copy link
Member

/cc @dcoutts

@gracjan
Copy link

gracjan commented Sep 22, 2013

Note that cabal-dev ghci does not expose this problem.

@nmk
Copy link

nmk commented Sep 25, 2013

Having the same problem with cabal repl. The exact error message is <stdin>: hGetChar: hardware fault (Input/output error).

@sol
Copy link
Member

sol commented Oct 7, 2013

For me this is kind of a show stopper. Which is unfortunate, because I really want to use cabal sandbox + would love to get rid of all the custom .ghci files in my projects.

Why is this so important to me? If you develop long running process (web services, etc.), you may want to start them from ghci, modify some code, hit ctrl-c, do a :reload, start it again, ...

@dagit
Copy link
Collaborator

dagit commented Oct 7, 2013

I think I've tracked this down to the way cabal spawns processes.

In cabal-dev the command that ultimately gets called to start ghci is System.Process.rawSystem. With cabal, I think, that it's using System.Process.runProcess.

Here is example code to show why I think this distinction matters:

import System.Process
import Control.Monad
import System.Exit

main = do
  exitcode <- rawSystem "ghci" []
  unless (exitcode == ExitSuccess) $ do
    exitFailure

  process <- runProcess "ghci" [] Nothing Nothing Nothing Nothing Nothing
  ec <- waitForProcess process
  unless (ec == ExitSuccess) $ do
    exitFailure

If you put that in a file and runhaskell on it, you will see that in the first ghci you can hit C-c as much as you want, but after you type :q and the second ghci starts up that hitting C-c will exit the process.

I tried to replace the call of runProcess in the Cabal sources to test out a bug fix (and hopefully send in a patch) but it's not working for me. Can someone who knows the Cabal sources try using rawSystem in the command that invokes ghci and test my theory? If it fixes the problem, then I think it indicates a bug in the process library.

@dagit
Copy link
Collaborator

dagit commented Oct 7, 2013

By searching for runProcess in Distribution/Simple/Program/GHC.hs and doing a quick hack to replace them with calls to rawSystem I've now tested my theory. runProcess is to blame.

It looks like runProcess is used precisely so that an environment can be passed to the process, whereas rawSystem doesn't allow that.

Now, what should we do about it?

@wereHamster
Copy link

Which version of cabal includes this fix?

@23Skidoo
Copy link
Member

@wereHamster Both HEAD and the 1.18 branch.

@gracjan
Copy link

gracjan commented Mar 2, 2015

Note: this strikes again.

@jsl
Copy link

jsl commented Mar 3, 2015

@gracjan which cabal version, and which interrupt are you seeing that kills cabal repl? I just tried with cabal 1.22.0, and Ctrl-C does not kill the repl, so this seems to be working fine for me.

@gracjan
Copy link

gracjan commented Mar 3, 2015

Unexpected: After Ctrl-C whole GHCi is terminated and bash prompt appears.

gracjan@computer:~/Sources/xxx:master$ cabal repl
Preprocessing executable 'xxx' for xxx-1.0...
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Prelude> :m +Control.Monad
Prelude Control.Monad> forever (return ())
^C
gracjan@computer:~/Sources/xxx:master$ 

Expected: After Ctrl-C prompt for GHCi appears again:

Prelude> :m +Control.Monad
Prelude Control.Monad> forever (return ())
^C
Prelude>

Version of cabal:

$ cabal --version
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library 

I do not know how to check which version of process was this particular cabal compiled.

@gracjan
Copy link

gracjan commented Mar 3, 2015

As a success story:

Prelude> :m +Control.Monad
Prelude Control.Monad> :m +Control.Concurrent
Prelude Control.Monad Control.Concurrent> forever (threadDelay 1000000)
^CInterrupted.
Prelude Control.Monad Control.Concurrent> 

So success!

That was after doing:

cabal install cabal-install --constraint 'process==1.2.2.0' --constraint 'Cabal<1.22.1.1'

(Note that Cabal==1.22.1.1 did not compile for me).

I do not know why installing 1.22 did not pull latest process 1.2.2 as dependency.

@qxjit
Copy link

qxjit commented Apr 10, 2015

Just tripped over this using cabal 1.22.2.0 with ubuntu trusty's stock ghc-7.6.3-10 package, which contains an older version of process. Installing cabal with a newer version of process as @gracjan shows above worked, as did using a newer ghc (7.10.1) version from the ppa repository (as described here: https://www.haskell.org/downloads/linux).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants