-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gracefully shutdown netty server (#5541)
- Loading branch information
1 parent
1650117
commit 8c65c50
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
airbyte-server/src/main/java/io/airbyte/server/ShutdownEventListener.java
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,41 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server; | ||
|
||
import io.micronaut.context.annotation.Value; | ||
import io.micronaut.context.event.ApplicationEventListener; | ||
import io.micronaut.runtime.event.ApplicationShutdownEvent; | ||
import jakarta.inject.Singleton; | ||
import java.lang.invoke.MethodHandles; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Listens for shutdown signal and keeps server alive for 20 seconds to process requests on the fly. | ||
*/ | ||
@Singleton | ||
public class ShutdownEventListener implements | ||
ApplicationEventListener<ApplicationShutdownEvent> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
@Value("${airbyte.shutdown.delay_ms}") | ||
private int shutdownDelayMillis; | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationShutdownEvent event) { | ||
logger.info("ShutdownEvent before wait"); | ||
try { | ||
// Sleep 20 seconds to make sure server is wrapping up last remaining requests before | ||
// closing the connections. | ||
Thread.sleep(shutdownDelayMillis); | ||
} catch (final Exception ex) { | ||
// silently fail at this stage because server is terminating. | ||
logger.warn("exception: " + ex); | ||
} | ||
logger.info("ShutdownEvent after wait"); | ||
} | ||
|
||
} |
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