question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow for graceful termination of the program started by sbt run

See original GitHub issue

Enabling cancelable in Global := true allows to press Ctrl+C and terminate the running program without terminating SBT, however the way how it is handled is quite surprising and doesn’t really do what is typically expected from Ctrl+C.

Ctrl+C sends the TERM signal to the application, not KILL. Unfortunately SBT behaves as if it was requested a KILL and interrupts the application. In forked mode, it also seems to kill the JVM very quickly after the application receives the TERM signal. This gives no way for the application to terminate gracefully as it would do when running without SBT supervision.

Hitting Ctrl+C inside of sbt run should pass the TERM signal to the running application and just let the application decide how it handles it. Most of applications know what to do. Maybe, if some users still insist on hard terminating of the process (if it was frozen or doesn’t respond to normal TERM), the second Ctrl+C would invoke the current behaviour and interrupt / kill the application.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:12
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Rasie1commented, Nov 30, 2019

I just put fork in Global := true to my build.sbt and now it works as expected. I can Ctrl+C my running process and it lets my code handle it. I also have cancelable in Global := true

0reactions
eatkinscommented, Nov 30, 2019

This can’t really be done in a platform independent way for the forked jvm. For in process run we can interrupt the main thread and the application will have an opportunity to recover and clean up after itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SBT stop run without exiting - Stack Overflow
I'm trying CTRL+C but it exits SBT. Is there a way to only exit the running application while keeping SBT open? scala ·...
Read more >
Running apps without blocking the task engine - Google Groups
In this solution, "run" forks off a server and the run task finishes. ... server. This can be used from command line sbt....
Read more >
Graceful termination • Akka HTTP - Documentation
Starting a graceful termination is as simple as invoking the terminate() method on the server binding: Scala: copy source import akka.actor.ActorSystem ...
Read more >
Start and stop a Scala application in production - Flurdy
Stopping and starting in SBT is easy, simply execute: run (or if using ... itself inside the JVM, and to gracefully shutdown inside...
Read more >
Handling ctrl+c in sbt shell - Akka
I believe that I need to implement a graceful shutdown hook for my jvm process running in sbt shell but the documents on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found