Skip to content

Commit 8842c08

Browse files
Benjamin Erichsenjenkins
authored andcommitted
util: Add a jvm shutdown hook to call app.quit()
Differential Revision: https://phabricator.twitter.biz/D1236932
1 parent 7d158ce commit 8842c08

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Runtime Behavior Changes
2525
and stack trace are printed to stderr in addition to the existing stdout. ``PHAB_ID=D1116753``
2626
* util-jvm: Memory manager & pool metrics are labelled dimensionally rather than hierarchically
2727
when exported as dimensional metrics. ``PHAB_ID=D1218090``
28-
28+
* util-app: Enables a jvm shutdown hook to call app.quit(). ``PHAB_ID=D1236932``
2929

3030
23.11.0
3131
-------

util-app/src/main/scala/com/twitter/finagle/util/flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ object loadServiceIgnoredPaths
5151
*/
5252
object enableJvmShutdownHook
5353
extends GlobalFlag[Boolean](
54-
false,
54+
true,
5555
"Registers a JVM shutdown hook which invokes close()"
5656
)

util-app/src/test/scala/com/twitter/app/AppTest.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import com.twitter.app.lifecycle.Event
55
import com.twitter.app.lifecycle.Observer
66
import com.twitter.app.LoadService.Binding
77
import com.twitter.conversions.DurationOps._
8+
import com.twitter.finagle.util.enableJvmShutdownHook
89
import com.twitter.util._
910
import java.util.concurrent.ConcurrentLinkedQueue
1011
import scala.jdk.CollectionConverters._
1112
import scala.language.reflectiveCalls
1213
import org.scalatest.funsuite.AnyFunSuite
14+
import org.scalatest.BeforeAndAfterEach
1315

1416
class TestApp(f: () => Unit) extends App {
1517
var reason: Option[String] = None
@@ -61,7 +63,12 @@ trait ErrorOnExitApp extends App {
6163
}
6264
}
6365

64-
class AppTest extends AnyFunSuite {
66+
class AppTest extends AnyFunSuite with BeforeAndAfterEach {
67+
68+
override protected def beforeEach(): Unit = {
69+
enableJvmShutdownHook.parse("false")
70+
}
71+
6572
test("App: make sure system.exit called on exception from main") {
6673
val test1 = new TestApp(() => throw new RuntimeException("simulate main failing"))
6774

0 commit comments

Comments
 (0)