File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import java.util.Objects
15
15
16
16
import scala .util .{Failure , Success , Try }
17
17
import scala .concurrent .{ExecutionContext , Future , Promise }
18
+ import scala .util .control .NonFatal
18
19
19
20
/** The base class for state machines generated by the `scala.async.Async.async` macro.
20
21
* Not intended to be directly extended in user-written code.
@@ -34,15 +35,14 @@ abstract class FutureStateMachine(execContext: ExecutionContext) extends Functio
34
35
/** Assign `i` to the state variable */
35
36
protected def state_= (s : Int ): Unit = state$async = s
36
37
38
+ NonFatal // eagerly classloading NonFatal to reduce the chance of a cascading StackOverflowError in `completeFailure`
39
+
37
40
/** Complete the state machine with the given failure. */
38
- protected def completeFailure (t : Throwable ): Unit = {
39
- //
40
- // TODO https://github.com/scala/scala-async/issues/243
41
- //
42
- // scala-async accidentally started catching NonFatal exceptions in:
43
- // https://github.com/scala/scala-async/commit/e3ff0382ae4e015fc69da8335450718951714982#diff-136ab0b6ecaee5d240cd109e2b17ccb2R411
44
- // This follows the new behaviour but should we fix the regression?
45
- result$async.complete(Failure (t))
41
+ protected def completeFailure (t : Throwable ): Unit = t match {
42
+ case NonFatal (t) =>
43
+ result$async.complete(Failure (t))
44
+ case _ =>
45
+ throw t
46
46
}
47
47
48
48
/** Complete the state machine with the given value. */
Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ class ExceptionalTest {
18
18
}
19
19
20
20
@ Test
21
- @ Ignore // TODO https://github.com/scala/scala-async/issues/243
22
21
def nonFatalNotCaughtAsync (): Unit = {
23
22
check { implicit ec =>
24
23
async {
You can’t perform that action at this time.
0 commit comments