Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hystrix plugin cause biz error #4857

Merged
merged 2 commits into from
Jun 7, 2020
Merged

fix hystrix plugin cause biz error #4857

merged 2 commits into from
Jun 7, 2020

Conversation

zifeihan
Copy link
Member

@zifeihan zifeihan commented Jun 4, 2020

Please answer these questions before submitting pull request


Bug fix

  • Bug description.
    this problem is, origin object HystrixConcurrencyStrategyDefault is wrapped to HystrixConcurrencyStrategy. under hystrix 1.4.3 com.netflix.hystrix.HystrixRequestLog#getCurrentRequest(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) this method doesn't check isCurrentThreadInitialized, but checked in other high version
  • How to fix?
    like hystrix high version, Return null if the {@link HystrixRequestContext} has not been initialized for the current thread.

New feature or improvement

  • Describe the details and related test reports.

@codecov
Copy link

codecov bot commented Jun 4, 2020

Codecov Report

Merging #4857 into master will increase coverage by 0.45%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4857      +/-   ##
============================================
+ Coverage     50.71%   51.17%   +0.45%     
- Complexity     2745     2754       +9     
============================================
  Files           752     1331     +579     
  Lines         18556    28926   +10370     
  Branches       1798     3159    +1361     
============================================
+ Hits           9411    14802    +5391     
- Misses         8394    13447    +5053     
+ Partials        751      677      -74     
Impacted Files Coverage Δ Complexity Δ
...ystrix/v1/SWHystrixConcurrencyStrategyWrapper.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...1/SWHystrixLifecycleForwardingRequestVariable.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...erver/receiver/envoy/MetricServiceGRPCHandler.java 12.16% <0.00%> (-77.84%) 2.00% <0.00%> (ø%)
...er/receiver/envoy/AccessLogServiceGRPCHandler.java 20.75% <0.00%> (-37.15%) 2.00% <0.00%> (ø%)
...skywalking/oap/server/core/alarm/AlarmMessage.java 66.66% <0.00%> (-33.34%) 2.00% <0.00%> (ø%)
...prometheus/provider/PrometheusFetcherProvider.java 32.25% <0.00%> (-30.25%) 8.00% <0.00%> (ø%)
...ient/elasticsearch/ElasticSearchInsertRequest.java 80.00% <0.00%> (-20.00%) 2.00% <0.00%> (ø%)
...ient/elasticsearch/ElasticSearchUpdateRequest.java 80.00% <0.00%> (-20.00%) 2.00% <0.00%> (ø%)
...ticsearch7/client/ElasticSearch7UpdateRequest.java 80.00% <0.00%> (-20.00%) 2.00% <0.00%> (ø%)
...ticsearch7/client/ElasticSearch7InsertRequest.java 83.33% <0.00%> (-16.67%) 2.00% <0.00%> (ø%)
... and 894 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3d907b...5ef0832. Read the comment docs.

@wu-sheng wu-sheng added this to the 8.0.0 milestone Jun 4, 2020
@wu-sheng wu-sheng added agent Language agent related. bug Something isn't working and you are sure it's a bug! plugin Plugin for agent or collector. Be used to extend the capabilities of default implementor. labels Jun 4, 2020
if (!HystrixRequestContext.isCurrentThreadInitialized()) {
return null;
}
return super.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this could be NPE, right? In some old versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super.get() method

public T get() {
        if (HystrixRequestContext.getContextForCurrentThread() == null) {
            throw new IllegalStateException(HystrixRequestContext.class.getSimpleName() + ".initializeContext() must be called at the beginning of each request before RequestVariable functionality can be used.");
        } else {
            ConcurrentHashMap<HystrixRequestVariableDefault<?>, HystrixRequestVariableDefault.LazyInitializer<?>> variableMap = HystrixRequestContext.getContextForCurrentThread().state;
            HystrixRequestVariableDefault.LazyInitializer<?> v = (HystrixRequestVariableDefault.LazyInitializer)variableMap.get(this);
            if (v != null) {
                return v.get();
            } else {
                HystrixRequestVariableDefault.LazyInitializer<T> l = new HystrixRequestVariableDefault.LazyInitializer(this);
                HystrixRequestVariableDefault.LazyInitializer<?> existing = (HystrixRequestVariableDefault.LazyInitializer)variableMap.putIfAbsent(this, l);
                return existing == null ? l.get() : existing.get();
            }
        }
    }

super.get() will trigger IllegalStateException, in some old versions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then next question is, why this method is being called? Is it called by SkyWalking plugin codes?

Copy link
Member Author

@zifeihan zifeihan Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is called by hystrix AbstractCommand constructor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is, the old version caller, AbstractCommand, should not call this, right? Otherwise, it triggers Illegal issue itself. Could you be more clear what context is missing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concurrencyStrategy is HystrixConcurrencyStrategyDefault instance in no skywalking agent, but skywalking plugin wrapped it to HystrixConcurrencyStrategy instance. not HystrixConcurrencyStrategyDefault. thus skip "concurrencyStrategy instanceof HystrixConcurrencyStrategyDefault" condition. i don't know where context be initialize, but when "concurrencyStrategy instanceof HystrixConcurrencyStrategyDefault" condition, it checkd this "HystrixRequestContext.isCurrentThreadInitialized()".
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, why don't we change the SkyWalking wrapper logic? It seems more reasonable, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With offline communication, right now, this seems the easiest solution w/o harm. I will keep this for now. Thanks.

@wu-sheng wu-sheng linked an issue Jun 7, 2020 that may be closed by this pull request
4 tasks
@wu-sheng wu-sheng merged commit f513c39 into apache:master Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent Language agent related. bug Something isn't working and you are sure it's a bug! plugin Plugin for agent or collector. Be used to extend the capabilities of default implementor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hystrix plugin cause biz error
2 participants