class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync {

	@Override
	public void onFatalError(Throwable exception) {
		TaskManagerExceptionUtils.tryEnrichTaskManagerError(exception);
		LOG.error("Fatal error occurred while executing the TaskManager. Shutting it down...", exception);

		// In case of the Metaspace OutOfMemoryError, we expect that the graceful shutdown is possible,
		// as it does not usually require more class loading to fail again with the Metaspace OutOfMemoryError.
		if (ExceptionUtils.isJvmFatalOrOutOfMemoryError(exception) &&
				!ExceptionUtils.isMetaspaceOutOfMemoryError(exception)) {
			terminateJVM();
		} else {
			closeAsync();

			FutureUtils.orTimeout(terminationFuture, FATAL_ERROR_SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS);

			terminationFuture.whenComplete(
				(Void ignored, Throwable throwable) -> terminateJVM());
		}
	}

	public  TaskManagerRunner(Configuration configuration, PluginManager pluginManager);

}