craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 634 forks source link

Segmentation Fault when implementing read/write query splitting #5625

Open christofer198 opened 4 years ago

christofer198 commented 4 years ago

Description

When trying to implement read/write query splitting using a custom database component like the one detailed in the docs (https://docs.craftcms.com/v3/config/app.html#cache-component), I keep hitting a seg fault on my server (Apache).

I'm running craft in a docker container in kubernetes and can provide my docker file if necessary.

Code

'components' => [
    'db' => function() {
        $config = craft\helpers\App::dbConfig();
        $config['slaveConfig'] = [
            'username' => 'root',
            'password' => getEnv('DB_PASSWORD'),
            'tablePrefix' => 'craft_',
            'attributes' => [
                PDO::ATTR_TIMEOUT => 10,
            ],
        ];

        $config['slaves'] = [
            ['dsn' => getEnv('SLAVE_DSN_1')], 
            ['dsn' => getEnv('SLAVE_DSN_2')],
        ];
        return Craft::createObject($config);
    },
],

After a little debugging it appears that the slave dsn declaration array is what's triggering the error but I'm unclear as to why a simple array declaration would be triggering the error. Any help would be appreciated, thanks!

Additional info

jasonmccallister commented 4 years ago

@christofer198 taking a quick glance at the code you provided and I see you are calling the function getEnv('DB_PASSWORD'). That should be getenv('DB_PASSWORD') instead (note the casing on the e).

Can you change the code to use getenv and see if the error persists?

christofer198 commented 4 years ago

@jasonmccallister Thanks for the reply. I've ahead and updated all of my getEnv to getenv in my app.php file and tested but the server still hits a segfault, unfortunately.

I should mention that even when using either syntax but with the slave dsn declarations commented out, the server executes requests just perfectly fine. So definitely seems like something is up with the slave dsn declarations.

angrybrad commented 4 years ago

Can you share the stack/details from the segfault? If you take it out of Kubernetes and just run it in Docker, does it work?

jasonmccallister commented 4 years ago

@christofer198 can you also verify that all of the environment variables are defined and not empty?