A cats-effect fiber, once started, a reference kept of it, some other code executed and then rejoined, won't raise the errors that happen inside.
Do you know why .join doesn't throw an error and why my application doesn't quit. Why will a thread remain running and the application stays hanging while also hiding the original error?
In my code
(for {
startedStreamsFiber <- List(
stream1,
stream2,
).parTraverse_(_.compile.drain).toResource.start
_ <- logger.info("Application has started").toResource
_ <- startedStreamsFiber.join
} yield ()).use_
if one of the inner streams raises an error such as
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint ...
the application won't fail, but stay on and keep logging:
Non-daemon threads currently preventing JVM termination: - 34: Thread[KQueueEventLoopGroup-2-1,10,main]
- - 38: Thread[DestroyJavaVM,5,main]
Non-daemon threads currently preventing JVM termination: - 34: Thread[KQueueEventLoopGroup-2-1,10,main]
- - 38: Thread[DestroyJavaVM,5,main]
Seems like the solution is to use
startedStreamsFiber.joinWithUnit. Simple as that..joindoesn't have the same error handling as.joinWith,.joinNeveror.joinWithUnit. It's the only one that doesn't propagate errors. This way it works and I get the nice stacktrace and the application quits.