BookStack icon indicating copy to clipboard operation
BookStack copied to clipboard

Page revisions list can exhaust memory/query limits with high item counts

Open rockenren opened this issue 1 year ago • 1 comments

Attempted Debugging

  • [X] I have read the debugging page

Searched GitHub Issues

  • [X] I have searched GitHub for the issue.

Describe the Scenario

We have a page with 1000+ revisions in count (and 650 rows in database), when trying to access this page revisions history, the error occurs (see logs below).

image

We already increased PHP and Nginx memory limits, but it's not working anymore. We are using Nginx + PHP 7.4 + MySQL from Ubuntu repos (5.7.38-0ubuntu0.18.04.1).

Exact BookStack Version

v22.07.2

Log Content

Nginx log:

2022/08/10 12:22:40 [error] 1523#1523: *3154 FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 1126400 bytes) in /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 373PHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php:368 Stack trace: #0 /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php(368): PDO->prepare() #1 /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php(705): Illuminate\Database\Connection->Illuminate\Database\{closure}() #2 /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php(672): Illuminate\Database\Connection->runQueryCallback() #3 /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php(376): Illuminate\Database\Connection->run() #4 /var/www/" while reading response header from upstream, client: <IP>, server: <SERVER>, request: "GET <URI>/revisions HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "<HOST>", referrer: "<URL>" 2022/08/10 12:22:40 [error] 1523#1523: *3154 FastCGI sent in stderr: "PHP message: PHP Warning: Packets out of order. Expected 147 received 79. Packe" while reading upstream, client: <IP>, server: <HOST>, request: "GET <URI>/revisions HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "<SERVER>", referrer: "<URL>" 2022/08/10 12:22:40 [error] 1523#1523: *3154 FastCGI sent in stderr: "t size=0 in Unknown on line 0" while reading upstream, client: <IP>, server: <SERVER>, request: "GET <URI>/revisions HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "<HOST>", referrer: "<URL>"

laravel.log:

[stacktrace] #0 {main} "} [2022-08-10 12:22:40] production.ERROR: Allowed memory size of 268435456 bytes exhausted (tried to allocate 1126400 bytes) {"userId":3,"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 268435456 bytes exhausted (tried to allocate 1126400 bytes) at /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connection.php:373)

PHP Version

7.4

Hosting Environment

Ubuntu 18.04.6 LTS, installed using official installation script.

rockenren avatar Aug 10 '22 08:08 rockenren

Thanks for reporting @rockenren,

I can confirm that data fetching for the revisions list display is done very inefficiently. The revision content is being loaded in, which it does not need to be for this view, hence exhausting memory limits.

I've assigned this to be addressed for the next patch release (Targeted for release tomorrow) to directly address these inefficiencies. I've also opened up #3638 as a longer-term improvement to dealing with high revision counts.

ssddanbrown avatar Aug 10 '22 13:08 ssddanbrown

This has now been addressed as part of 031c67ba58923872a1a6e8cd5bbae593b8e87377 and will be part of the next patch release as mentioned above. I'll therefore close this off but please still comment if you continue to experience any issues after updating once the release has been deployed.

ssddanbrown avatar Aug 10 '22 16:08 ssddanbrown

Can confirm, issue is resolved after updating to v22.07.3. Thank you.

rockenren avatar Aug 11 '22 14:08 rockenren

@rockenren Awesome, thanks for confirming!

ssddanbrown avatar Aug 11 '22 14:08 ssddanbrown