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

Program stuck when Layer return error #3956

Closed
pshemass opened this issue Jul 10, 2020 · 2 comments · Fixed by #3994
Closed

Program stuck when Layer return error #3956

pshemass opened this issue Jul 10, 2020 · 2 comments · Fixed by #3994

Comments

@pshemass
Copy link

pshemass commented Jul 10, 2020

I found really weird behavior in ZLayer with >+>

ZIO version: 1.0.0-R21-2

import zio._
import zio.console._
import zio.clock._

object LayerStuck extends zio.App {

  val env =
    ZLayer.fromEffect(ZIO.effect(1/0)) ++ ((Console.live ++ Clock.live) >+> ZLayer.fromManaged(
      ZManaged
        .makeEffect {
          //This can be anything that take time to initialize for me it was ActorSystem
          Thread.sleep(5000)
          println("open")
        }{_ => Thread.sleep(5000); println("closed")}
    ))

    def run(args: List[String]) =
      ZIO.unit.as(ExitCode.success)
        .provideCustomLayer(env)
        .catchAll(cause => putStrLn("error: " + cause).as(ExitCode.failure)) <* putStrLn("the end")

}

for given code I'm getting output below and program never ends.

error: java.lang.ArithmeticException: / by zero
the end
open
closed

if I change >+> to >>> program works as expected and exit with code 1

open
closed
error: java.lang.ArithmeticException: / by zero
the end

one more observation is that if I changed putStrLn("the end") to putStrLn("the end").delay(10.seconds) program complete as expected.

@adamgfraser
Copy link
Contributor

I'm wondering if this could be related to #3940.

@pshemass
Copy link
Author

pshemass commented Jul 14, 2020

there is a chance they are related because it seems that with >+> init code is async ( not really sure if this is expected ).

error: java.lang.ArithmeticException: / by zero
the end
open //this should be on the top
closed

but there is chance that this is different too. this delay putStrLn("the end").delay(10.seconds) which helps here doesn't help for snippet in #3940

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

Successfully merging a pull request may close this issue.

2 participants