Gateway 访问超时 返回504

Posted mengjianzhou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gateway 访问超时 返回504相关的知识,希望对你有一定的参考价值。

问题梳理

【现象】Gateway访问超时

    "timestamp": "2019-06-29 11:45:13",
    "path": "/admin/user/info",
    "status": 504,
    "error": "Gateway Timeout",
    "message": "Response took longer than configured timeout"
【方法】 根据出错位置查看源代码,

AbstractCommand->

HystrixObservableTimeoutOperator->

final Reference tl = HystrixTimer.getInstance().addTimerListener(listener);

  1. 看到有时间监听类
public Reference<TimerListener> addTimerListener(final TimerListener listener) 
        startThreadIfNeeded();
        // add the listener

        Runnable r = new Runnable() 

            @Override
            public void run() 
                try 
                    listener.tick();
                 catch (Exception e) 
                    logger.error("Failed while ticking TimerListener", e);
                
            
        ;

        ScheduledFuture<?> f = executor.get().getThreadPool().scheduleAtFixedRate(r, listener.getIntervalTimeInMilliseconds(), listener.getIntervalTimeInMilliseconds(), TimeUnit.MILLISECONDS);
        return new TimerReference(listener, f);
    

2.找到关键点

    listener.getIntervalTimeInMilliseconds()

3.接着看lister的实现

        @Override
        public int getIntervalTimeInMilliseconds() 
            return properties.timerDelayInMilliseconds().get();
        

4.找到properties关键类

HystrixCollapserProperties

5.终于找到了关键属性

timerDelayInMilliseconds

 protected HystrixCollapserProperties(HystrixCollapserKey key, Setter builder, String propertyPrefix) 
        this.maxRequestsInBatch = getProperty(propertyPrefix, key, "maxRequestsInBatch", builder.getMaxRequestsInBatch(), default_maxRequestsInBatch);
        this.timerDelayInMilliseconds = getProperty(propertyPrefix, key, "timerDelayInMilliseconds", builder.getTimerDelayInMilliseconds(), default_timerDelayInMilliseconds);
        this.requestCacheEnabled = getProperty(propertyPrefix, key, "requestCache.enabled", builder.getRequestCacheEnabled(), default_requestCacheEnabled);
        this.metricsRollingStatisticalWindowInMilliseconds = getProperty(propertyPrefix, key, "metrics.rollingStats.timeInMilliseconds", builder.getMetricsRollingStatisticalWindowInMilliseconds(), default_metricsRollingStatisticalWindow);
        this.metricsRollingStatisticalWindowBuckets = getProperty(propertyPrefix, key, "metrics.rollingStats.numBuckets", builder.getMetricsRollingStatisticalWindowBuckets(), default_metricsRollingStatisticalWindowBuckets);
        this.metricsRollingPercentileEnabled = getProperty(propertyPrefix, key, "metrics.rollingPercentile.enabled", builder.getMetricsRollingPercentileEnabled(), default_metricsRollingPercentileEnabled);
        this.metricsRollingPercentileWindowInMilliseconds = getProperty(propertyPrefix, key, "metrics.rollingPercentile.timeInMilliseconds", builder.getMetricsRollingPercentileWindowInMilliseconds(), default_metricsRollingPercentileWindow);
        this.metricsRollingPercentileWindowBuckets = getProperty(propertyPrefix, key, "metrics.rollingPercentile.numBuckets", builder.getMetricsRollingPercentileWindowBuckets(), default_metricsRollingPercentileWindowBuckets);
        this.metricsRollingPercentileBucketSize = getProperty(propertyPrefix, key, "metrics.rollingPercentile.bucketSize", builder.getMetricsRollingPercentileBucketSize(), default_metricsRollingPercentileBucketSize);
    

Gateway的超时是通过Hystrix的属性控制的Orz

方向错了,赶紧换个方向

https://www.cnblogs.com/520playboy/p/8074347.html

总结

一直想找Gateway的属性,试了半天,网上各种找都没找到,最后还是通过看源码,发现方向错误了,调整方向,bingo.

以上是关于Gateway 访问超时 返回504的主要内容,如果未能解决你的问题,请参考以下文章

接口请求报错 504 Gateway Time-out

nginx 出现504 Gateway Time-out的解决方法

Nginx 代理设置连接超时解决504 gateway timeout

带有 Eureka 的 Spring Cloud Gateway 得到 504(网关超时)

504 Gateway Time-out

网页出现“504 Gateway Time-out”,没有其它信息是啥原因?