-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
MariaDB service crashes since updating to Laravel 11 oom-kill possible memory leak in Laravel 11? #50807
Comments
Hey there, Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out. Thanks! |
No worries. Created https://stackoverflow.com/questions/78238067/mariadb-service-crashes-since-updating-to-laravel-11-oom-kill-possible-memory-le for reference |
@driesvints Followed the advice on Stackoverflow. I'm being pushed back here mate :)
Hoping to see if others get a similar problem |
You need to use the new |
Sure, I used Laravel Shift a few days ago to update. It didn't change or mention anything about this. Does this mean I need to migrate all Right now I see first party packages like Pulse continuing to use Note, after changing |
If you use mariadb you should best use that connection. This will make sure you don't deviate from it in the future. You should update your uuid columns as in the upgrade guide. If it's the same problem then that's most likely not it. You're also free to stay on mysql if you really want that. @hafezdivandari @staudenmeir do any of you have any ideas what could cause the memory for the new MariaDB connection to blow up like above? @sts-ryan-holton can you please add more info to reproduce this? What sort of queries/usage is causing this? |
I've switched to I updated to Laravel 11 and deployed the changes. Then almost 24 hours after the deployment, My server has always ran at around 75-90% memory. When it crashed, moments before the memory usage went up to around 98% and fell over, I restarted and 24 hours later to this morning, same thing happened. And I've never had this happen ever despite running hot on memory. I run:
CPU utilisation is never really that high, and when running This morning, I updated my droplet at a £30 monthly increase to double my CPU and memory. The server has been rebooted to perform that change earlier. Earlier this morning when opening this issue, look at the memory usage:
And right now:
Over 1.5GB extra consumed over just 5 hours? I have another project that's got around 4 database queues running Laravel 10, it's been up for over a week and is at 1.0GB, and I've observed this project over an hour, it goes up to 1.1GB then back down to 1.0GB. Also worth mentioning, I haven't made any config overrides to My worry here is that something in Laravel 11 is causing an increase in memory usage. Laravel Shift recommended I add the following back after
And of course, I removed |
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
Just checked another server too running Centos. Except, not Laravel, it's at 1.1GB over 1 month. So I have:
|
Does this server only run MariaDB or your whole application? How does the number of active connections develop over time? Does it only increase or stay in the same range?
I don't really see how Laravel could cause these crashes since it "only" sends queries to MariaDB. Laravel itself doesn't allocate any database memory or run background tasks inside the database. #50044 is the "most fundamental" change in Laravel 11 I can think of, but I haven't seen any other reports of increased memory usage.
This mostly (or even only) affects migration queries.
The MySQL and MariaDB driver are identical except for the UUID column type (which only affects migration queries for new columns). |
The server runs MariaDB, and the whole application. It also runs a Nuxt-JS 2.x front-end. I've checked the number of incoming HTTPD connections and it's only 7. And Google Analytics doesn't show many on the site. I've ran I experience both problems on Since my comment 2 hours ago which stated: "Memory: 2.5G" I've checked again now: "Memory: 3.1G" so has been rising. I fear a third crash imminent over night since updating to Laravel 11. What about configs? Service providers? These are both changes in Laravel 11. I don't really want to have to set up a cron to auto-restart |
You updated both at the same time? |
I updated PHP to 8.3 from 8.2 about an hour before. Another note about |
May be related to queue? Do you have any queued jobs? What is your queue driver? |
I'm using Laravel Horizon as my queue. Which goes through Redis v7. But Redis never crashed when mariadb crashed. Utilisation of redis never peaked either. My Redis is a "managed database" provided by Digital Ocean. Here's the past 24 hours view. And the crash happened at 8am this morning. As for queues, it's not overly busy compared to some platforms. Unless Horizon is connecting to the DB and some change there? |
Can you go back to PHP 8.2 but keep Laravel 11? |
Whether this is any use: Locally, using Laravel Sail, PHP 8.3, MySQL 5.7 ( Over a 5 minute period, looking within Docker Desktop on the MySQL container, the memory usage graph in here has gone up over the 5 minute period: It started at: 226MB at 19:30, and and risen to: 236MB by 19:35, an increase of 10MB in 5 minutes? With very little workload I don't want this to distract from the issue. Maybe there's something up with tasks being scheduled in Laravel 11. Meanwhile, production now at 3.3GB memory usage |
A bit unrelated, but I encountered a similar issue, but not with database but with php itself being oom-killed once I switched to php 8.3. In my case It was due to some image manipulations I had to perform. I had to limit the max image size being produced to not go over 2000x2000. Still. on php 8.2 worked fine with larger images. |
Database memory rose by 3GB over night. It's now sitting at 6.1GB |
Is the database used by anything else besides the Laravel application? Did you recently update MariaDB or change its configuration? Are you using any "special" features like procedures or triggers? For some people, switching to |
It is not
At least once a week, if not, once bi-weekly I try to run a
I've spent a few hours this morning digging further. I did come across SHOW GLOBAL VARIABLES LIKE 'version_malloc_library'; It outputs "system". After some googling on how to install it, I edited
Restarted the database server. And Upon rebooting, memory output was 260MB. That was some half hour ago roughly, and now we're sitting at 702MB. So it's still rising. I would hope it doesn't go beyond 1.1GB since my other application running Laravel 10 doesn't go beyond this. Interestingly, when running I'll switch back to PHP 8.3 whilst I'm here. I feel that there's something in Laravel 11 making excessive connections to the DB? |
The queue worker would be my first (and really only) suspect, but since you are using Redis, it only uses database for batching and storing failed jobs, AFAIK. Are you using batching or do you have a lot failed jobs/retries? Besides that, Laravel should only connect to the database once for every user request. |
I'm not using job batching. In the past hour Horizon has processed 43,536 jobs, and 4 failures. Of which, the retry attempts is at 2 for each. I tried pausing Horizon for a brief moment (hard to do in production systems) to see whether the memory usage would drop, and it didn't. But I agree with the idea that the queue worker could be doing something. Yes it connects to Redis, but then Redis has to have an open connection to that database. Could it be failing to close the connection or creating a Just checked in on MariaDB's memory usage and currently:
|
@sts-ryan-holton if you stop the queue worker all together and monitor if the memory usage goes up? That way we'll know for sure. |
I ran Over that time, the number of tasks remains at 91, memory at 1.1G, and CPU at 16m. Here's the status after bringing supervisor back up. Of course, the built up jobs would result in the higher server memory usage here. Other than that, no change sadly. In addition, I reached out to the hosting provider Digital Ocean to get their thoughts. They're pointing back to the application |
So it's definitely the queue workers. @sts-ryan-holton the next thing we can try is using Laravel's queue worker directly instead of horizon. What happens if you start processing jobs through the queue worker and leave horizon stopped? |
As in me manually running |
yeah, take horizon out of the scope entirely and see if the Laravel queue worker has the same issue. |
Okay, I'll run the same test as above, except have three separate tabs and run the following:
Essentially manually running them, I'll report back the same types of screenshots |
Okay, same test performed, except I manually ran the queue workers. The three separate queue worker tabs running the commands above all successfully run without any errors thrown in the output.
|
Then it's horizon most likely, not Laravel. Or maybe a combo of both. Do you still know which version of horizon you were on before you made the upgrade to Laravel v11? |
Prior to the upgrade, I was on:
Post upgrade...
|
@sts-ryan-holton can you try to downgrade to Horizon 5.23.1 and laravel v11.0.7 and see if the issue persists? |
I've downgraded Laravel to 11.0.7 and Horizon to 5.23.1. I had to also downgrade Pulse to Beta 15 from 16 as it required at least 11.0.8. Memory of database prior to restart: 1.4GB I've restarted Horizon, cleared config and cache. I've also restarted straight after restarting mariadb:
|
Within a minute of restarting mariadb service, task count and memory has already risen:
|
Thanks. I'm sorry but I'm out of ideas. Right now this doesn't seem Laravel or Horizon related to me but something specifically with your app since we don't have any other reports and Laravel v11 has already been live for a month. I'm going to close this one for now but if there's more reports coming in we could have another look. Anyone's still free to help you out either here or somewhere else. |
I've reverted back to 11.1.1 framework and latest Horizon v5. On PHP 8.3. The only thing then I can think of is to setup a cron to manually restart mariadb once a day, or sooner. I'm hoping others come across this, it's quite a major thing |
@driesvints @staudenmeir Okay, since the last comment I posted, something interesting has happened here. One thing I observed within the
One suggestion I was given was to run Anyhow, I ran systemctl show mariadb.service | grep "MemoryCurrent" | awk -F= '{printf "%.0f\n", $2/1024/1024}' I then performed the upgrade, whilst:
And logged the memory afterwards:
Since then, I've woken this morning, it's been around 13 hours now, and the memory usage right now is:
Previously it would've been over 6gb. Note I don't now have excessive errors in the logs, but query whether Laravel 11, since it doesn't use the dbal package anymore, whether, the errors I was experiencing related to I am still using |
It sounds like MariaDB was upgraded without mysql_upgrade being run, and that something related to the MariaDB upgrade was causing the memory issue, coincidentally with (but possibly exacerbated by queries run by) the Laravel upgrade. You mention dnf, so I assume Fedora. I haven't used Fedora in forever.. but it sounds like you can use 'dnf history list' to show package history (ref) - I believe it would be 'dnf history list mariadb-server'. Can you please run that and post the results? It's worth noting that, unless there is a bug in the database server, nothing that Laravel (or any other database client) does should be able to cause the server to use more than the configured memory amounts/etc. It sounds like your MariaDB instance is probably configured to use more memory than your system can actually support; I suspect that if the buffer sizes/connection pool limits/etc were configured to the limits you expect, even with this issue the database server probably would not have run out of memory - but instead would have started running into major performance issues once all memory available to it was allocated, which would have hopefully made this issue easier to debug. ref - note that MariaDB's recommendations for memory utilization and such usually are written with the expectation that MariaDB is the sole process on a system/container - so adjust accordingly. For what it's worth, here's another reference to MariaDB running poorly with similar symptoms until mysql_upgrade is run: home-assistant/core#87811 In any case - you'll probably want to make sure that whatever method you use to keep your system up to date will either only allow minor release upgrades for critical processes, or else ensure that things like mysql_upgrade will automatically be run upon major upgrades. Edit: also, just as context - the mysql.* tables are internal tables that are used internally by the database for any number of purposes, and can also be directly queried. In this case, it was probably MariaDB's optimizer referencing those tables to figure out the best query execution plan for whatever queries were being run by Laravel. |
Laravel Version
11.1.0
PHP Version
8.3.4
Database Driver & Version
MariaDB 10.11
Description
Hi 👋
I thought I'd just mention this in case anyone else has experienced this since updating to Laravel 11.
I use MariaDB 10.11 in production. Since updating, I'm seeing that my database has been crashing. I've been running my server for a few years now, and it's always been operating on the latest Laravel version, and also has been fine sitting between 75% and 90% memory utilisation (8GB).
Steps To Reproduce
Two noticeable things are different in Laravel 11 compared to Laravel 10:
I wanted to figure out whether I'm missing anything. As a result of this, at a cost, I've had to increase my server's memory. I do wonder whether there's a memory leak in how the driver works now in Laravel 11?
It's been almost 3 hours since rebooting my database server, and I'm seeing the memory usage here at 1GB
The text was updated successfully, but these errors were encountered: