当前位置:网站首页>On the problem of class member variable pollution in the context of one-time concurrence
On the problem of class member variable pollution in the context of one-time concurrence
2022-06-21 09:46:00 【dddyge】
The technical framework of the project I maintain is php Based on swoole One of the web The framework is called swoft. The framework is a collaborative environment , And imitate springboot An annotated php frame . I made a demand , The problem of class member variable pollution in the context of concurrency occurs . The accident is like this : Launch once rpc request , The returned result has a member variable of the class , However, it is found that the requested parameters do not match the results , I checked the error log first , Nothing unusual , Then check the request execution log , It is found that the number of logs is lost . So I looked at the code carefully , I pass the results to the member variables of each class through the responsibility chain pattern , and BeanFactory::getBean By default, this method gets the class of the singleton , So the member variables of the class are polluted by other coroutines without protection . Knowing this question , I modified the annotation , Change each class of the responsibility chain to the multiple instance pattern . Use locally Jmeter The result of pressure measurement is correct , However, a new problem is found, that is, the execution log is lost . I checked it carefully later swoft in log Implementation of package , I found that the framework development team also made the same mistake as me . His idea here is : Store the log in the member variable of the class messages in , This is an array , When the number of elements in this array is greater than the number of disks , Brush the log records in the array into the file . But there is no code block protection for thread synchronization , Therefore, in the case of concurrency, the problem of missing logs caused by overwriting can be reproduced . I was thinking that the development team of the framework should not make such a mistake . So I turned it over github Of swoft Framework of the issue, Found in 20 This question has been raised since , But it has not been repaired . I looked at the source code later , Find him log This bean It's the singleton mode , That's why messages Member variables are polluted , I created a new newLogger Class and set it as the log processing class when the framework starts , The problem of concurrent pollution is solved .
Through the thinking of this accident :1. The framework development team may not be right , Even this github 5k Much of the star There are also a large number of unsolved problems ( Eat the melon : be based on swoole Of web Most of the frameworks seem to follow swoole There is a conflict of interest among the people in the underlying development team, resulting in no one willing to be based on swoole To develop the framework .).2. The framework of mysql Connection pooling is not particularly good , There is no mechanism to keep the connection alive , Often output on the terminal log mysql has gone away Error of , The error is because mysql server The connection was closed , But the code level still regards the connection as a normal connection to send data , So I made such a mistake .
There are two related issue Link to :
https://github.com/swoft-cloud/swoft/issues/1430.
https://github.com/swoft-cloud/swoft/issues/1367. The problem of log duplication can be solved by writing a simple interface , Just print it directly 4 Logs , then 10 Concurrent access by threads , It doesn't have to be 40 Logs are printed , This result is sufficient to prove the problem of CO process pollution class member variables .
边栏推荐
- 【实战】STM32 FreeRTOS移植系列教程7:FreeRTOS 事件标志组
- 异常
- Polymorphic & class object & registered factory & Reflection & dynamic proxy
- Form Validation
- 并发编程高级部分:并行流,Tasks和Executors以及CompletableFuture类
- 【实战】STM32 FreeRTOS移植系列教程1:FreeRTOS 二值信号量使用
- The R language uses the fix function to modify the name of the data variable through the editor. For example, use the fix function to modify the name of the dataframe data column
- Ccs7.3 how to erase only part of the flash sector when burning DSP on-chip flash (two projects of on-chip flash burning of a DSP chip)
- Judge the data type of JS
- Vscode high-speed download address -- solve the problem of slow vscode Download
猜你喜欢

Unity中的地平面简介

Stm32mp1 cortex M4 Development Chapter 11: expansion board buzzer control

Stm32mp1 cortex M4 Development Part 9: expansion board air temperature and humidity sensor control

Observation on the salary data of the post-90s: poor, counselled and serious

DSP gossip: how to save the compiled variables on the chip when the variables are defined in the code

1. is god horse a meta universe?
![[actual combat] STM32 FreeRTOS migration series tutorial 7: FreeRTOS event flag group](/img/1c/10add042271c11cd129ddfce66f719.jpg)
[actual combat] STM32 FreeRTOS migration series tutorial 7: FreeRTOS event flag group

Lodash real on demand approach

为什么 C# 访问 null 字段会抛异常?

【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
随机推荐
Solve the problem of error when typescript object gets value
音视频格式简介、编解码、音视频同步
Introduction and template of segment tree Foundation (I)
118. summary of basic knowledge of typescript (data type, interface, abstract class, inheritance, attribute encapsulation, modifier)
Versions supported by vuforia engine
abnormal
R language through rprofile Site file, user-defined configuration of R language development environment startup parameters, shutdown parameters, user-defined specified cran local image source download
How to select embedded hands-on projects and embedded open source projects
Float floating layout clear floating
Style penetration of vant UI components -- that is, some styles in vant UI components cannot be modified
It is only seven days since the commencement of construction in 2022. I left the outsourcing company
115. secondary packaging of table components
多态&Class对象&注册工厂&反射&动态代理
Stm32mp1 cortex M4 development part 12: expansion board vibration motor control
111. solve the problem of prohibiting scripts from running on vs code. For more information, see error reporting
2. the development of the meta universe
Unity中的地平面简介
【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
【实战】STM32 FreeRTOS移植系列教程7:FreeRTOS 事件标志组
Eureka的TimedSupervisorTask类(自动调节间隔的周期性任务)