-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch fatal exceptions in futures (#4223)
Fixes #4221 Otherwise they just silently terminate the future and leave downstream `Await`s hanging, resulting in the process hanging waiting for a future that will never complete. `def reportFailure` doesn't seem to log stuff properly when this happens for some reason Covered with additional integration tests
- Loading branch information
Showing
3 changed files
with
119 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package build | ||
import mill._ | ||
|
||
def fatalException(msg: String) = { | ||
// Needs to be a fatal error according to scala.util.control.NonFatal, | ||
// not just any error! | ||
val ex = new java.lang.LinkageError(msg) | ||
assert(!scala.util.control.NonFatal.apply(ex)) | ||
ex | ||
} | ||
def fatalTask = Task{ | ||
throw fatalException("CUSTOM FATAL ERROR IN TASK") | ||
123 | ||
} | ||
|
||
def alwaysInvalidates = Task.Input(math.random()) | ||
def fatalCloseWorker = Task.Worker{ | ||
alwaysInvalidates() | ||
new AutoCloseable { | ||
override def close(): Unit = | ||
throw fatalException("CUSTOM FATAL ERROR ON CLOSE") | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
integration/failure/fatal-error/src/CompileErrorTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package mill.integration | ||
|
||
import mill.testkit.UtestIntegrationTestSuite | ||
|
||
import utest._ | ||
|
||
object CompileErrorTests extends UtestIntegrationTestSuite { | ||
val tests: Tests = Tests { | ||
test - integrationTest { tester => | ||
val res = tester.eval("fatalTask") | ||
|
||
assert(res.isSuccess == false) | ||
assert(res.err.contains("""java.lang.LinkageError: CUSTOM FATAL ERROR IN TASK""")) | ||
|
||
// Only run this test in client-server mode, since workers are not shutdown | ||
// with `close()` in no-server mode so the error does not trigger | ||
if (clientServerMode) { | ||
// This worker invalidates re-evaluates every time due to being dependent on | ||
// an upstream `Task.Input`. Make sure that a fatal error in the `close()` | ||
// call does not hang the Mill process | ||
tester.eval("fatalCloseWorker") | ||
val res3 = tester.eval("fatalCloseWorker") | ||
assert(res3.err.contains("""java.lang.LinkageError: CUSTOM FATAL ERROR""")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters