Presto: SIGTERM doesn't wait GracefulShutdownHandler completion

Created on 30 Nov 2017  路  3Comments  路  Source: prestodb/presto

Steps to reproduce this problem:

  • Set /v1/info/state to SHUTTING_DOWON for invoking GracefulShutdownHandler
  • Run launcher.py stop sends TERM signal to JVM and it will start LifeCycleManager.stop process (Guice injected modules will start @PreDestroy processes)

Problem:

Question: @nezihyigitbasi
GracefulShutdownHandler should be aware of SIGTERM? If so GracefulShutdownHandler should have @PreDestroy shutdown hook to wait task completion and its state synchronization to the coordinator.

This simplifies lifecycle management of Presto worker processes. For example, for autoscaling, we only need to set SHUTTING_DOWN state and run launcher.py stop for graceful scaling-in of presto worker nodes.

Most helpful comment

You shouldn't ever have to send SIGTERM (or run launcher stop). GracefulShutdownHandler should forcibly terminate the JVM after a 30s timeout using System.exit(0) in DefaultShutdownAction. Is it not existing on it's own?

Handling SIGTERM in this manner is very difficult. When the JVM receives SIGTERM, it starts all the shutdown hooks which will run concurrently in an arbitrary order. Airlift LifeCycleManager.stop() is triggered via a shutdown hook, which will run all of the @PreDestroy methods in reverse creation order.

In order to reliably block in shutdown, we'd want to add a handler to LifeCycleManager that gets run at the start of the stopping phase. The order in which @PreDestroy methods get called is too arbitrary for this.

However, there's still the problem that all the other shutdown hooks will run, and there's no telling what effect that might have on various libraries. For example, I think the HDFS code does cleanup using them, so it's likely anything Hadoop file system related would break.

All 3 comments

You shouldn't ever have to send SIGTERM (or run launcher stop). GracefulShutdownHandler should forcibly terminate the JVM after a 30s timeout using System.exit(0) in DefaultShutdownAction. Is it not existing on it's own?

Handling SIGTERM in this manner is very difficult. When the JVM receives SIGTERM, it starts all the shutdown hooks which will run concurrently in an arbitrary order. Airlift LifeCycleManager.stop() is triggered via a shutdown hook, which will run all of the @PreDestroy methods in reverse creation order.

In order to reliably block in shutdown, we'd want to add a handler to LifeCycleManager that gets run at the start of the stopping phase. The order in which @PreDestroy methods get called is too arbitrary for this.

However, there's still the problem that all the other shutdown hooks will run, and there's no telling what effect that might have on various libraries. For example, I think the HDFS code does cleanup using them, so it's likely anything Hadoop file system related would break.

@electrum Thanks for the comment. Actually, we don't need to call launcher stop, but we sometimes see the following error in the coordinator log if we terminate EC2 instances after the graceful shutdown:

Dec  1 03:06:22 ip-172-18-153-237 presto[15387]: 2017-12-01T03:06:22.339Z#011WARN#011TaskInfoFetcher-20171201_025133_00501_rdjpk.2.1-996#011com.facebook.presto.server.remotetask.RequestErrorTracker#011Error getting info for task 20171201_025133_00501_rdjpk.2.1: java.net.NoRouteToHostException: No route to host: http://172.18.148.95:8081/v1/task/20171201_025133_00501_rdjpk.2.1

And this causes the query failure (usually PAGE_TRANSPORT_TIMEOUT, etc.). We will try adding more grace period before shutting down the instance.

I understand adding shutdown hook for GracefulShutdownHandler could be tricky because we usually need to start the termination process of the other modules as well such as Hadoop related components as you mentioned.

No further action is necessary for this. I'll close this ticket. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haozhun picture haozhun  路  4Comments

yaxxie picture yaxxie  路  4Comments

shigechuanqi picture shigechuanqi  路  3Comments

aminalaee picture aminalaee  路  3Comments

tesseract2048 picture tesseract2048  路  3Comments