swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

PDO::prepare: Socket#41 has already been bound to another coroutine#2, reading of the same socket in multiple coroutines at the same time is not allowed Stack trace: #632

Closed hihozhou closed 5 years ago

hihozhou commented 5 years ago
Q A
Bug report? no
Feature request? yes/no
Swoft version master(2.x)
Swoole version 4.3.3
PHP version 7.2.17
Runtime environment Ubuntu 18.04.

Details

ab 压测数据库查询报错


[2019-05-14 16:22:42 $31955.0]  WARNING swManager_check_exit_status: worker#2[pid=32051] abnormal exit, status=255, signal=0
[2019-05-14 16:22:42 *32052.2]  ERROR   (PHP Fatal Error: 10002):
PDO::prepare: Socket#42 has already been bound to another coroutine#3, reading of the same socket in multiple coroutines at the same time is not allowed
Stack trace:
#0  PDO->prepare() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Connection/Connection.php:390]
#1  Swoft\Db\Connection\Connection->Swoft\Db\Connection\{closure}() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Connection/Connection.php:628]
#2  Swoft\Db\Connection\Connection->runQueryCallback() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Connection/Connection.php:599]
#3  Swoft\Db\Connection\Connection->run() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Connection/Connection.php:398]
#4  Swoft\Db\Connection\Connection->select() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Query/Builder.php:2370]
#5  Swoft\Db\Query\Builder->runSelect() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#6  Swoft\Db\Query\Builder_5cda7acff1114->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#7  Swoft\Db\Query\Builder_5cda7acff1114->__proxyCall() called at [/tmp/Builder_5cda7acff1114.php:449]
#8  Swoft\Db\Query\Builder_5cda7acff1114->runSelect() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Query/Builder.php:2354]
#9  Swoft\Db\Query\Builder->Swoft\Db\Query\{closure}() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Query/Builder.php:2852]
#10 Swoft\Db\Query\Builder->onceWithColumns() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#11 Swoft\Db\Query\Builder_5cda7acff1114->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#12 Swoft\Db\Query\Builder_5cda7acff1114->__proxyCall() called at [/tmp/Builder_5cda7acff1114.php:545]
#13 Swoft\Db\Query\Builder_5cda7acff1114->onceWithColumns() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Query/Builder.php:2355]
#14 Swoft\Db\Query\Builder->get() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#15 Swoft\Db\Query\Builder_5cda7acff1114->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#16 Swoft\Db\Query\Builder_5cda7acff1114->__proxyCall() called at [/tmp/Builder_5cda7acff1114.php:445]
#17 Swoft\Db\Query\Builder_5cda7acff1114->get() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Eloquent/Builder.php:633]
#18 Swoft\Db\Eloquent\Builder->getModels() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Eloquent/Builder.php:617]
#19 Swoft\Db\Eloquent\Builder->get() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Concern/BuildsQueries.php:96]
#20 Swoft\Db\Eloquent\Builder->first() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Eloquent/Builder.php:391]
#21 Swoft\Db\Eloquent\Builder->find() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/stdlib/src/Helper/PhpHelper.php:37]
#22 Swoft\Stdlib\Helper\PhpHelper::call() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Eloquent/Model.php:1094]
#23 Swoft\Db\Eloquent\Model->__call() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/db/src/Eloquent/Model.php:1108]
#24 Swoft\Db\Eloquent\Model::__callStatic() called at [/home/hiho/www/onehourx/store/app/Http/Controller/Small/AuthController.php:121]
#25 App\Http\Controller\Small\AuthController->login() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#26 App\Http\Controller\Small\AuthController_5cda7ad0173c3->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#27 App\Http\Controller\Small\AuthController_5cda7ad0173c3->__proxyCall() called at [/tmp/AuthController_5cda7ad0173c3.php:29]
#28 App\Http\Controller\Small\AuthController_5cda7ad0173c3->login() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/stdlib/src/Helper/PhpHelper.php:37]
#29 Swoft\Stdlib\Helper\PhpHelper::call() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/Middleware/DefaultMiddleware.php:101]
#30 Swoft\Http\Server\Middleware\DefaultMiddleware->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/Middleware/DefaultMiddleware.php:57]
#31 Swoft\Http\Server\Middleware\DefaultMiddleware->process() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#32 Swoft\Http\Server\Middleware\DefaultMiddleware_5cda7acfc6c70->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#33 Swoft\Http\Server\Middleware\DefaultMiddleware_5cda7acfc6c70->__proxyCall() called at [/tmp/DefaultMiddleware_5cda7acfc6c70.php:37]
#34 Swoft\Http\Server\Middleware\DefaultMiddleware_5cda7acfc6c70->process() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/RequestHandler.php:73]
#35 Swoft\Http\Server\RequestHandler->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#36 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#37 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->__proxyCall() called at [/tmp/RequestHandler_5cda7acfd9d0e.php:25]
#38 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/Middleware/ValidatorMiddleware.php:60]
#39 Swoft\Http\Server\Middleware\ValidatorMiddleware->process() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#40 Swoft\Http\Server\Middleware\ValidatorMiddleware_5cda7acfc5d32->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#41 Swoft\Http\Server\Middleware\ValidatorMiddleware_5cda7acfc5d32->__proxyCall() called at [/tmp/ValidatorMiddleware_5cda7acfc5d32.php:27]
#42 Swoft\Http\Server\Middleware\ValidatorMiddleware_5cda7acfc5d32->process() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/RequestHandler.php:73]
#43 Swoft\Http\Server\RequestHandler->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#44 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#45 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->__proxyCall() called at [/tmp/RequestHandler_5cda7acfd9d0e.php:25]
#46 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/Middleware/UserMiddleware.php:63]
#47 Swoft\Http\Server\Middleware\UserMiddleware->process() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#48 Swoft\Http\Server\Middleware\UserMiddleware_5cda7acfc631f->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#49 Swoft\Http\Server\Middleware\UserMiddleware_5cda7acfc631f->__proxyCall() called at [/tmp/UserMiddleware_5cda7acfc631f.php:27]
#50 Swoft\Http\Server\Middleware\UserMiddleware_5cda7acfc631f->process() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/RequestHandler.php:73]
#51 Swoft\Http\Server\RequestHandler->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#52 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#53 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->__proxyCall() called at [/tmp/RequestHandler_5cda7acfd9d0e.php:25]
#54 Swoft\Http\Server\RequestHandler_5cda7acfd9d0e->handle() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/HttpDispatcher.php:57]
#55 Swoft\Http\Server\HttpDispatcher->dispatch() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#56 Swoft\Http\Server\HttpDispatcher_5cda7acfd8cec->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#57 Swoft\Http\Server\HttpDispatcher_5cda7acfd8cec->__proxyCall() called at [/tmp/HttpDispatcher_5cda7acfd8cec.php:22]
#58 Swoft\Http\Server\HttpDispatcher_5cda7acfd8cec->dispatch() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/http-server/src/Swoole/RequestListener.php:36]
#59 Swoft\Http\Server\Swoole\RequestListener->onRequest() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:53]
#60 Swoft\Http\Server\Swoole\RequestListener_5cda7acfd3ba6->__invokeTarget() called at [/home/hiho/www/onehourx/store/vendor/swoft/component/src/aop/src/Concern/AopTrait.php:30]
#61 Swoft\Http\Server\Swoole\RequestListener_5cda7acfd3ba6->__proxyCall() called at [/tmp/RequestListener_5cda7acfd3ba6.php:21]
<?php

namespace App\Model\Entity;

use Swoft\Db\Eloquent\Model;
use Swoft\Db\Annotation\Mapping\Column;
use Swoft\Db\Annotation\Mapping\Entity;
use Swoft\Db\Annotation\Mapping\Id;

/**
 * Class Account
 *
 * @since 2.0
 *
 * @Entity(table="account")
 */
class Account extends Model
{

    /**
     * @Id()
     *
     * @Column(name="id", prop="id")
     * @var int|null
     */
    private $id;

    /**
     * @return int|null
     */
    public function getId(): ?int
    {
        return $this->id;
    }

    /**
     * @param int|null $id
     */
    public function setId(?int $id): void
    {
        $this->id = $id;
    }

}
$account = Account::find(1);
ab -n 10000 -c 2000   http://0.0.0.0:18306/
hihozhou commented 5 years ago

发现查询前没有加DB::beginTransaction();就会报上面错误

stelin commented 5 years ago

@hihozhou 感谢你的反馈,我们尽快修复。

stelin commented 5 years ago

@hihozhou 已修复,更新最新代码测试

hihozhou commented 5 years ago

Thank