apache / apache/servicecomb-java-chassis

addLocalContext(parentContext.getLocalContext());多线程问题Concurrentmodificationexception Bug

Open
#3,323 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.9k
Forks
814
Avg merge
8d 23h
Merged PRs (30d)
1

Description

这个类有构造这个代码:
org.apache.servicecomb.swagger.invocation.SwaggerInvocation#SwaggerInvocation
public SwaggerInvocation() {
parentContext = ContextUtils.getInvocationContext();
if (parentContext != null) {
addContext(parentContext.getContext());
addLocalContext(parentContext.getLocalContext());
}
}

其中addLocalContext(parentContext.getLocalContext()); 里面调用了localContext.putAll(otherContext);
这个在多线程环境,业务代码自己开多线程调用下游服务传递上下文会有多线程问题,报Concurrentmodificationexception异常
建议使用public void setLocalContext(Map localContext)直接设置上下文

或者将
protected Map context = new HashMap<>();

protected Map localContext = new HashMap<>();

都换成ConcurrentMap

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at org.apache.servicecomb.swagger.invocation.SwaggerInvocation#SwaggerInvocation and inspect addLocalContext, especially the localContext.putAll call described in the issue. Compare the proposed context-handling alternatives and verify that concurrent downstream calls do not raise ConcurrentModificationException while propagating local context.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.