Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Connecting to Postgres - Laravel #514

Closed
JohnDotOwl opened this issue Jan 27, 2024 · 9 comments
Closed

Crash on Connecting to Postgres - Laravel #514

JohnDotOwl opened this issue Jan 27, 2024 · 9 comments

Comments

@JohnDotOwl
Copy link

JohnDotOwl commented Jan 27, 2024

When the following database connection code is enable , it will crash the whole octane running franken without any error

$data = DB::table('test')->get();

Command used to run FrankenPHP

php artisan octane:start --caddyfile /var/www/test/Caddyfile --server=frankenphp --log-level=debug

If i run it with ./frankenphp run , it will return the following and crash
Segmentation fault

I've installed
sudo apt-get install php8.3-pgsql
sudo apt-get install php8.3-pdo

Update : I've tested it on ARM initially, now x86, it's the same issue.

@JohnDotOwl JohnDotOwl changed the title Crash on Connecting to PostgresqlDB - Laravel Crash on Connecting to Postgres - Laravel Jan 27, 2024
@withinboredom
Copy link
Collaborator

Possibly also related to #458.

@mmccall10
Copy link

FWIW I have a similar issue on a mac M2 with laravel and postgresql. It works fine connecting to a local db but when I attempt to connect using a DATABASE_URL to something like a neon endpoint I get this error.

frankenphp(8451,0x175243000) malloc: double free for ptr 0x13300c200
frankenphp(8451,0x175243000) malloc: *** set a breakpoint in malloc_error_break to debug

@dunglas
Copy link
Owner

dunglas commented Jan 29, 2024

This should probably be reported to static-php-cli, or to PHP itself. This smells like an upstream bug.

@withinboredom
Copy link
Collaborator

withinboredom commented Jan 29, 2024

I've installed
sudo apt-get install php8.3-pgsql
sudo apt-get install php8.3-pdo

I suspect this is the issue since AFAIK, apt doesn't install php's thread safe libraries.

@dunglas
Copy link
Owner

dunglas commented Jan 30, 2024

Debian packages aren't used and it's useless to install them.

Octane installs the static binary we provide, which is built using ZTS and doesn't use local PHP extensions.

@kkovacs
Copy link

kkovacs commented Feb 25, 2024

Hello, first of all, thanks for the great job you are doing with FrankenPHP, @dunglas !

I'm experiencing the same segfault on pg_connect with the precompiled frankenphp binary, but the postgres connection works with the docker version of FrankenPHP. So it's not an upstream issue, probably? => apparently it IS an upstream issue, I managed to reproduce it with static-php-cli. I'v submitted an issue there: crazywhalecc/static-php-cli#353

Reproduced with:

  • Ubuntu 22.04 (clean VM)
  • PostgreSQL 14 (Ubuntu 22.04 default), 16 (latest, PPA)
  • FrankenPHP: 1.1.0, 1.0.2, 1.0.1, 1.0.0

Contents of index.php:

<?php
pg_connect("postgresql://root:xxxxx@127.0.0.1/postgres");
  1. segfault from php-cli:
# ./frankenphp-linux-x86_64 php-cli index.php
Segmentation fault (core dumped)
  1. segfault from php-server:
# wget https://github.com/dunglas/frankenphp/releases/download/v1.1.0/frankenphp-linux-x86_64
# chmod 755 frankenphp-linux-x86_64
# ./frankenphp-linux-x86_64 php-server
2024/02/25 18:37:46.277       WARN    admin   admin endpoint disabled
2024/02/25 18:37:46.278 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0001d5080"}
2024/02/25 18:37:46.278 WARN    http.auto_https server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "php", "http_port": 80}
2024/02/25 18:37:46.280 INFO    http.log        server running  {"name": "php", "protocols": ["h1", "h2", "h3"]}
2024/02/25 18:37:46.280 INFO    FrankenPHP started 🐘   {"php_version": "8.3.3"}
2024/02/25 18:37:46.281 INFO    Caddy serving PHP app on :80
2024/02/25 18:37:46.292 WARN    tls     storage cleaning happened too recently; skipping for now        {"storage": "FileStorage:/root/.local/share/caddy", "instance": "6f0de059-811e-440a-861f-08b240d7cb33", "try_again": "2024/02/26 18:37:46.292", "try_again_in": 86399.999999001}
2024/02/25 18:37:46.292 INFO    tls     finished cleaning storage units

# curl http://127.0.0.1/index.php
curl: (52) Empty reply from server
[1]+  Segmentation fault      (core dumped) ./frankenphp-linux-x86_64 php-server
  1. BUT! What's super strange is, that in the docker version, it works (AFTER installing the pgsql extension with /usr/local/bin/install-php-extensions pgsql):
# docker run -it --rm -v $PWD:/app/public -p 80:80   dunglas/frankenphp bash
[we are in the docker now]
$ /usr/local/bin/install-php-extensions pgsql
[...long output of installing...]
$ /usr/local/bin/frankenphp php-cli index.php
$

No segfault this time (and I confirmed that I can run SQL over the connection).

(Without the install-php-extension it of course says Fatal error: Uncaught Error: Call to undefined function pg_connect() in /app/public/index.php:3)

@kkovacs
Copy link

kkovacs commented Feb 26, 2024

Just a small update and workaround, based on the thread in static-php-cli: the bug seems related to a TLS issue, it doesn't surface if sslmode=disable is supplied in the connection string (if you can afford that):

<?php
$conn = pg_connect("postgresql://root:xxxxx@127.0.0.1/postgres?sslmode=disable");

@kkovacs
Copy link

kkovacs commented Feb 26, 2024

Heads up: the bug was fixed upstream in crazywhalecc/static-php-cli#353 in static-php-cli, so hopefully in the next frankenphp build it should be fixed too (if it will use static-php-cli 2.1.1 or above).

@dunglas
Copy link
Owner

dunglas commented Feb 26, 2024

Thank you for getting this fixed @kkovacs!

@dunglas dunglas closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants