h$shutdownHaskellAndExit doesn't work in browser, resulting with infinite loops #225

Closed
osa1 opened this Issue Jul 18, 2014 · 8 comments

Projects

None yet

3 participants

@osa1
Contributor
osa1 commented Jul 18, 2014

Originally reported by trap_exit on IRC. Currently this bug is also blocking me.

This simple program:

main = error "hello"

Fails to terminate on Chrom/Chromium and probably others. It prints "If you can read this, shutdownHaskellAndExit did not exit." forever:

https://github.com/ghcjs/ghcjs-boot/blob/master/patches/base.patch#L395

The problem is caused by this function in shims/pkg/base.js:

function h$shutdownHaskellAndExit(code, fast) {
    if(typeof process !== 'undefined' && process.exit) {
        process.exit(code);
    } else if(typeof quit !== 'undefined') {
        quit(code);
    }
}

I think we need to somehow signal main loop to stop in this function, instead of forcing process to exit. 1) It may not possible to do that in browsers 2) even in node or other interpreters, stopping GHCJS main loop is different that terminating the whole app and I think what we should be doing is just stopping the GHCJS main loop and let rest of the program continue running.

@luite
Member
luite commented Jul 18, 2014

We actually need to exit the process here, since we have to set the exit status. threads started with h$main terminate the whole program when they finish, threads started with h$run don't. In most cases, users will want h$main, but we should document the alternative.

I've fixed it now by not letting browsers use the same top handler

@luite
Member
luite commented Jul 18, 2014

ok, apparently not fixed. i'll check again

@luite luite added the bug label Jul 18, 2014
@luite
Member
luite commented Jul 18, 2014

works correctly after all

@luite luite closed this Jul 18, 2014
@broma0
broma0 commented Oct 19, 2015

I'm still experiencing this using Google Chrome and Chromium on the latest commit (as of writing this):

main = error "hello"

Was this fixed?

@luite
Member
luite commented Oct 19, 2015

I fixed this some time ago, but reintroduced it later, when I changed the default main action in runmain.js (this makes it work if main is reexported, and adds more exception handling).

I pushed a fix for the new bug recently, but missed some things required to make it work if GHCJS_BROWSER is defined. Should also be fixed now, let me know if you still see it.

@broma0
broma0 commented Oct 19, 2015

Still seeing this with a rebuild of ghcjs.

git clone https://github.com/ghcjs/ghcjs.git
cabal install ./ghcjs
cd ghcjs
ghcjs-boot --dev

I'm compiling this code:

main = error "infinite loop"

With the following command:

ghcjs -DGHCJS_BROWSER

I've also attempted this in larger project managed with cabal by setting:

cpp-options: -DGHCJS_BROWSER:

The same issue arises.

I looked around and saw a commit in ghcjs/shims that seem to address the issue. Is that the fix you're talking about?

@luite
Member
luite commented Oct 19, 2015

Yes the fix is in shims. If you're doing a dev build, you can get the latest commits in shims by cleaning first: ghcjs-boot --dev --clean. But since there aren't any library changes, you actually don't need to rebuild anything. Just go to ~/.ghcjs/someversion/ghcjs/shims and git pull the latest commits.

@broma0
broma0 commented Oct 19, 2015

Confirmed working. Thanks!

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