Skip to content

【bug】熔断降级的异常比例为1时,不会被隔离 #128

Closed

Description

@aBreaking

extends #109
你好!上次关于#109的这个bug,后来被整改了。

Bug描述

但是整改得并不正确.....经我测试,仅限于异常比例小于1的情况下正确。
但是当抛出的异常比例为100%时,设定的阈值小于1,此时会出现DegradeException,但是服务不会进入timeWindow被隔离。

举个栗子

同样以com.alibaba.csp.sentinel.demo.degrade.ExceptionRatioDegradeDemo这个Demo为例,直接设定每次都抛出异常,结果如下(不知怎么上传图片,直接copy过来了):
Connected to the target VM, address: '127.0.0.1:51393', transport: 'socket' begin to statistic!!! 1536131534343, oneSecondTotal:34, oneSecondPass:5, oneSecondBlock:29, oneSecondBizException:5 1536131535345, oneSecondTotal:49, oneSecondPass:5, oneSecondBlock:44, oneSecondBizException:5 1536131536345, oneSecondTotal:48, oneSecondPass:5, oneSecondBlock:43, oneSecondBizException:5 1536131537344, oneSecondTotal:48, oneSecondPass:5, oneSecondBlock:43, oneSecondBizException:5 1536131538346, oneSecondTotal:49, oneSecondPass:5, oneSecondBlock:44, oneSecondBizException:5 1536131539346, oneSecondTotal:48, oneSecondPass:5, oneSecondBlock:43, oneSecondBizException:5 1536131540346, oneSecondTotal:48, oneSecondPass:5, oneSecondBlock:43, oneSecondBizException:5 1536131541348, oneSecondTotal:49, oneSecondPass:5, oneSecondBlock:44, oneSecondBizException:5 1536131542348, oneSecondTotal:48, oneSecondPass:5, oneSecondBlock:43, oneSecondBizException:5

整改措施

问题还是出在:com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule的passCheck方法中,在原来的Fixed处:commit 6799da2

double realSuccess = success - exception;  //186
            if (realSuccess <= 0) {   //187
                return exception < RT_MAX_EXCEED_N;
            }

不应该修改,还是应该保留原来的代码:

if (success <= 0) {
                return exception < RT_MAX_EXCEED_N;
            }

请确认...

Activity

  1. sczyh30 commented on Sep 5, 2018

    @sczyh30
    Member

    Thanks for reporting! This is due to the early return when no success and exception count does not exceed the threshold. We'll fix it later.

  2. added
    kind/bugCategory issues or prs related to bug.
    on Sep 5, 2018
  3. added this to the 0.2.0 milestone on Sep 5, 2018
  4. aBreaking commented on Sep 5, 2018

    @aBreaking
    Author

    by the way,问下哈。目前的熔断降级策略是每秒钟的异常比例不能超过阈值。
    那么我怎么设置这个单位时间呢?
    比如,我设置每分钟或者每30秒的异常的比例不超过阈值,超过则隔离。
    我试着修改,com.alibaba.csp.sentinel.node.IntervalProperty的INTERVAL值,但是好像结果并不是我想要的。
    能告知一下这个怎么做吗?
    谢谢!

  5. sczyh30 commented on Sep 5, 2018

    @sczyh30
    Member

    Hi, this is not supported well in current version. You can modify the INTERVAL but it will affect the global counter.

  6. added a commit that references this issue on Sep 19, 2018
    7b9c032
  7. added a commit that references this issue on Jan 8, 2019
    3d08446
  8. added a commit that references this issue on May 17, 2025
    ed30f85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategory issues or prs related to bug.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions