HystrixRunTimeException: <操作> 超时和回退失败

Posted

技术标签:

【中文标题】HystrixRunTimeException: <操作> 超时和回退失败【英文标题】:HystrixRunTimeException: <operation> timed-out and fallback failed 【发布时间】:2017-03-07 17:12:07 【问题描述】:

我使用的是 hystrix 1.3.7,并且我的 hystrix 命令也定义了一个备用方法。所以设置如下:

public final Optional<ImageData> run() throws Exception 
 // does api call to get resized image from a service


@Override
public final Optional<ImageData> getFallback() 
    // falls back to processing the image locally.

但是,我意识到有时(不是所有时间)Hystrix 发生超时时,它似乎没有执行 getFallback 方法中的逻辑并抛出 HsytrixRuntimeException。这是堆栈跟踪:

com.netflix.hystrix.exception.HystrixRuntimeException: imageResize timed-out and fallback failed.
at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:980)
at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:59)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:595)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:587)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:77)
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70)
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70)
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:1121)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57)
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:1138)
at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

这可能是因为 hystrix 配置不正确吗?任何帮助将不胜感激。

【问题讨论】:

尝试将您的代码放入 try/catch 中的getFallback 并记录抛出的异常。从日志中我会说那里会引发异常 【参考方案1】:

从错误日志中,我了解到您的 run() 方法失败并调用了回退。您在后备中的逻辑似乎也失败了。建议是,回退应该以永远不会失败的方式编码。如果失败,请检查您的后备代码。要么在回退中处理故障,要么只是将逻辑移出回退。

【讨论】:

以上是关于HystrixRunTimeException: <操作> 超时和回退失败的主要内容,如果未能解决你的问题,请参考以下文章

spring boot 项目启动 com.netflix.hystrix.exception.HystrixRuntimeException:timed-out and fallback failed

spring boot 项目启动 com.netflix.hystrix.exception.HystrixRuntimeException:timed-out and fallback failed

spring boot 项目启动 com.netflix.hystrix.exception.HystrixRuntimeException:timed-out and fallback failed

Hystrix 命令因“超时且没有可用的回退”而失败

SpringCloud服务消费者第一次调用出现超时问题的解决方案