openswoole / ext-openswoole

Programmatic server for PHP with async IO, coroutines and fibers
https://openswoole.com
Apache License 2.0
808 stars 51 forks source link

ClientPool concurrency issue with PDO. Queried data conflicts. #320

Open elarmust opened 1 year ago

elarmust commented 1 year ago
  1. What did you do? If possible, provide a simple script for reproducing the error. Run large number of mysql queries in parallel inside http server on('request') method.

Step 1: Create a ClientPool like this. image

Step 2: Create a wrapper function to query data and manage connection: image

Step 3: Run large number of parallel queries. For example, create a basic http server and query the data like this. image

Step 4: Open the website in 2 different browsers at the same time.

  1. What did you expect to see? Each request receives the correct data. For simple visual data verification, I used PHPSESSID cookie.
3. What did you see instead?

Data is getting mixed up between multiple queries running in parallel. image

4. What version of OpenSwoole are you using (show your `php --ri openswoole`)?

official docker image version 22.0.0

5. What is your machine environment used (show your `uname -a` & `php -v` & `gcc -v`) ?

Linux 66d70d353f35 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 Linux

PHP 8.2.5 (cli) (built: Apr 14 2023 18:00:14) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.5, Copyright (c) Zend Technologies

/bin/sh: gcc: not found ????

Additionally, this error is not reproducible when running them in parallel like this: image

This issue did not show up when i tried Swoole