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

Parallel requests and Exception handling #116

Open
z0isch opened this issue Apr 25, 2018 · 7 comments
Open

Parallel requests and Exception handling #116

z0isch opened this issue Apr 25, 2018 · 7 comments

Comments

@z0isch
Copy link

z0isch commented Apr 25, 2018

The program below logs the error when using 4.0.0, but when I upgrade to 5.0.0 it no longer logs the error

module Main where

import Prelude

import Control.Monad.Aff (Aff, launchAff)
import Control.Monad.Aff.Console (log, logShow)
import Control.Monad.Eff.Exception (EXCEPTION, error)
import Control.Monad.Error.Class (throwError, try)
import Control.Parallel (parallel, sequential)
import Data.Tuple (Tuple(..))
import Network.HTTP.Affjax (AJAX, get)

getPostbin :: forall eff.  Aff (exception :: EXCEPTION, ajax :: AJAX | eff) String
getPostbin = do
  resp <- get "http://postb.in/BgIt83CL"
  void $ throwError (error "Oops")
  pure resp.response

main = void $ launchAff do
    t <- try $ sequential $ Tuple <$> parallel getPostbin <*> parallel getPostbin
    logShow t
@garyb
Copy link
Member

garyb commented Apr 25, 2018

Is it the "Oops" error you're expecting to see? This is down to a change in Aff rather than affjax, and I think it may be intentional. /cc @natefaubion

@z0isch
Copy link
Author

z0isch commented Apr 25, 2018

Yeah, I'd like to catch the oops error. If I just do a delay instead of the get I can catch the error, so that's why I kinda assumed it would be an issue with affjax.

@garyb
Copy link
Member

garyb commented Apr 25, 2018

Hmm maybe you're right then! I just took a look at the diff between v4 and v5, and although it's "just" the aff update it wasn't entirely straight forward.

@safareli
Copy link
Contributor

safareli commented Apr 28, 2018

can you see the error if you do main = runAff_ log do ...?

@z0isch
Copy link
Author

z0isch commented Apr 30, 2018

Unfortunately it's still not showing with that change

@natefaubion
Copy link
Collaborator

This is probably #112. When running things in parallel, if one throws an exception the runtime will cancel the other fibers. However cancellation is broken, and so the canceller never yields, hanging it.

@garyb
Copy link
Member

garyb commented May 27, 2018

@natefaubion as per #117 (comment), with a fixed canceller this is still broken, but definitely seems to be in Aff now:

purescript-affjax\output\Effect.Aff\foreign.js:83
        throw error;
        ^

TypeError: Cannot read property 'constructor' of null
    at Object.isLeft (purescript-affjax\output\Effect.Aff\index.js:76:112)
    at join (purescript-affjax\output\Effect.Aff\foreign.js:720:16)
    at purescript-affjax\output\Effect.Aff\foreign.js:778:19
    at purescript-affjax\output\Effect.Aff\foreign.js:669:29
    at runEff (purescript-affjax\output\Effect.Aff\foreign.js:80:7)
    at run (purescript-affjax\output\Effect.Aff\foreign.js:496:15)
    at purescript-affjax\output\Effect.Aff\foreign.js:333:19
    at drain (purescript-affjax\output\Effect.Aff\foreign.js:120:9)
    at Object.enqueue (purescript-affjax\output\Effect.Aff\foreign.js:141:11)
    at purescript-affjax\output\Effect.Aff\foreign.js:330:27

Should we open an issue there?

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

Successfully merging a pull request may close this issue.

4 participants