Thread bloodshed caused by improper use shared variables

Let me talk about business :

Pre-orders need to send some information to the token and other risk control review. Orders are orders of physical and virtual two independent API interface.

ThreadLocal thread token information is on the shared variable, by RpcContext implicit transfer of dubbo fathom reached background. Get token sent backstage risk control review.

Talk about problems , there have been many virtual online orders to send a token kind of orders, and the repetition rate is relatively high.

The reason : a virtual orders by mistake, do not set the token to ThreadLocal thread shared variable. When the result in getting token back, take to the left in the thread token-kind set of orders. Since tomcat thread pool multiplexing, high repetition rate case it will appear.

Process substantially as follows:

Analysis of difficulties :

Because the token is sensitive information, the production environment can not print to the log, test environment due to frequent restarts, a lot of thread variable initialization order is not physical, it is a virtual order to obtain the token is empty. No problems in production can be reproduced.

Knowledge of the issues involved, or more:

1, tomcat threading model

2, threads share variables

3, dubbo inter-service mass participation

 

Guess you like

Origin www.cnblogs.com/daghai/p/10966712.html