title: Ktor server crashes when I press "stop" in IntelliJ IDEA
body: <p>When I press &quot;stop&quot; in <strong>IntelliJ IDEA</strong> to shutdown my <strong>Ktor</strong> app, it crashes with errors:</p>
  <pre><code>Closing daemon's stdin at end of input.
  HandleCancel processing Build{id=9b020945-b350-4d12-ba2d-c2e61531d515, currentDir=/Projects/blah-blah/server}
  The daemon will no longer process any standard input.
  Marking the daemon as canceled, address: [c267f21c-ecbb-4990-b647-de5cbe654b4a port:51722, addresses:[localhost/127.0.0.1]]
  The daemon has received a build cancellation request.
  
  &gt; Task :ApplicationKt.main() FAILED
  :ApplicationKt.main() (Thread[Execution worker for ':',5,main]) completed. Took 5.12 secs.
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':ApplicationKt.main()'.
  &gt; Build cancelled while executing task ':ApplicationKt.main()'
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
  
  * Get more help at https://help.gradle.org
  
  BUILD FAILED in 5s
  </code></pre>
  <p>I understand that <strong>Gradle</strong> was executing <code>run</code> task (<code>build</code> in logs, what's the hack?) and I interrupted its work by <code>SIGINT</code> from IDE. However, this is not behaviour that I need. I just want to my server could correctly start when I press &quot;run&quot; and shutdown when I press &quot;stop&quot;.</p>
  <p><strong>build.gradle:</strong></p>
  <pre><code>plugins {
      id 'application'
      id 'org.jetbrains.kotlin.jvm' version '1.6.10'
      id 'org.jetbrains.kotlin.plugin.serialization' version '1.6.10'
  }
  
  def ktor_version='1.6.7'
  def exposed_version = '0.37.3'
  
  group 'com.company'
  version '0.0.3'
  
  application {
      mainClass = 'io.ktor.server.netty.EngineMain'
  }
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      implementation 'org.jetbrains.kotlin:kotlin-stdlib'
      // Ktor
      implementation &quot;io.ktor:ktor-server-core:$ktor_version&quot;
      implementation &quot;io.ktor:ktor-server-netty:$ktor_version&quot;
      implementation &quot;io.ktor:ktor-serialization:$ktor_version&quot;
      implementation 'org.jetbrains.kotlinx:kotlinx-datetime:0.3.1'
      // Logging
      implementation 'ch.qos.logback:logback-classic:1.2.10'
      // Database
      implementation 'com.zaxxer:HikariCP:5.0.1'
      implementation &quot;org.jetbrains.exposed:exposed-core:$exposed_version&quot;
      implementation &quot;org.jetbrains.exposed:exposed-kotlin-datetime:$exposed_version&quot;
      runtimeOnly &quot;org.jetbrains.exposed:exposed-jdbc:$exposed_version&quot;
      implementation 'org.postgresql:postgresql:42.3.1'
      // Dependency injection
      implementation 'org.kodein.di:kodein-di-framework-ktor-server-jvm:7.10.0'
  }
  </code></pre>
  <p><strong>Application.kt:</strong></p>
  <pre><code>fun main(args: Array&lt;String&gt;): Unit = io.ktor.server.netty.EngineMain.main(args)
  
  @Suppress(&quot;unused&quot;)
  fun Application.module(@Suppress(&quot;UNUSED_PARAMETER&quot;) testing: Boolean = false) {
      installDi()
      install(ContentNegotiation) {
          json(Json {
              prettyPrint = true
          })
      }
      installErrorHandlers()
      installRoutes()
  }
  </code></pre>
  <p>And <strong>Run configuration</strong>:
  <a href="https://i.stack.imgur.com/pHvZS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pHvZS.png" alt="Screenshot" /></a></p>
  <p>Why does this error happen? How to fix it?</p>