YunoHost-Apps / wallabag2_ynh

Wallabag v2 package for YunoHost
https://www.wallabag.org/
GNU Affero General Public License v3.0
63 stars 13 forks source link

500 errors on YunoHost base upgrade, php7.3->php7.4, "Cannot redeclare mb_str_split()" #162

Closed mcint closed 1 month ago

mcint commented 1 year ago

Describe the bug

500 errors on wallabag2 endpoint after upgrade to YunoHost 11.0.

Context

Steps to reproduce

Performed yunohost base upgrade

Expected behavior

A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.

Logs

After noticing an issue, I attempted to create a back up. XD https://paste.yunohost.org/raw/mazuroneji

args:
  apps:
  - wallabag
  description: null
  dry_run: true
  methods: null
  name: null
  output_directory: null
  system: null
ended_at: 2023-01-29 05:09:04.716894
error: Nothing to save
interface: cli
operation: backup_create
parent: null
related_to: []
started_at: 2023-01-29 05:09:04.687980
success: false
yunohost_version: 11.0.11

============

2023-01-29 05:09:04,705: ERROR - wallabag will not be saved

I've manually exported data $ mysqldump db_name > backup-file.sql per mariaDB backup docs.

mcint commented 1 year ago

Attempting a workaround by installing the app anew (on another domain). I'll try to restore data into that database.

This also just causes 500s—although different 500s. The original wallabag app, hereafter W1 and new app W2:

mcint commented 1 year ago

In /etc/php/7.4/fpm/pool.d: ; YunoHost note : this file was automatically moved from /etc/php/7.3/fpm/pool.d

And in /var/log/nginx/[fqdn]-error.log, I found an error, hundreds, thousands of `2023/01/29 05:30:03 [error] 25576#25576: 4195 FastCGI sent in stderr: "PHP message: PHP Fatal error: Cannot redeclare mb_str_split() in /var/www/wallabag2/vendor/wallabag/php-mobi/MOBIClass/RecordFactory.php on line 119" while reading response header from upstream, client: 1.2.3.4, server: [fqdn], request: "GET /wallabag/ HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm-wallabag2.sock:", host: "[fqdn]", referrer: "https://[fqdn]/yunohost/sso/"`

The core error looks related to upstream app. PHP message: PHP Fatal error: Cannot redeclare mb_str_split() in


Per https://stackoverflow.com/a/64303980/1020467 I've resolved my issue by updating /var/www/wallabag2/vendor/wallabag/php-mobi/MOBIClass/RecordFactory.php to conditionally define

if (!function_exists('mb_str_split')) {
    function mb_str_split($str, $length = 1) 
    {
        // ...
    }
}

Deletion would work too. Though not backward compatible.

mcint commented 1 year ago

I don't know how this file and error fits in to the cascade of management layers (and I'm happy not to have to find out). I see sources/patches but nothing that touches php files. I hope this file is vendored-in as opposed to running the latest composer install or whatever is used.

Should this be resoled with a new patch in sources/patch or a new snapshot of upstream?

lapineige commented 1 year ago

First time I've heard about this issue, this is really strange O_o

No sure about the patch :thinking:

biosaat commented 1 year ago

And in /var/log/nginx/[fqdn]-error.log, I found an error, hundreds, thousands of `2023/01/29 05:30:03 [error] 25576#25576: 4195 FastCGI sent in stderr: "PHP message: PHP Fatal error: Cannot redeclare mb_str_split() in /var/www/wallabag2/vendor/wallabag/php-mobi/MOBIClass/RecordFactory.php on line 119" while reading response header from upstream, client: 1.2.3.4, server: [fqdn], request: "GET /wallabag/ HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm-wallabag2.sock:", host: "[fqdn]", referrer: "https://[fqdn]/yunohost/sso/"`

I am getting the same error messages, each time I try to access Wallabag. The app returns error 500. The Web application does not load and returns a blank page.

lapineige commented 1 year ago

Just in case, could you restart php7.4-fpm service ?

lapineige commented 1 year ago

So in #166 we can "reproduce" this error while upgrading from php7.4 to 8.0. That seems to be a bug occurring when different php versions are used before/after the upgrade.

biosaat commented 1 year ago

I restarted php7.4-fpm service but the issue remains.

mcint commented 1 month ago

It appears this mb_str_split method is removed from php after 7.3. (According to mb_str_split docs and attached comments, the inverse is true. However, for PHP < 7.4, "symfony/polyfill-mbstring" provided it. Looks like it could've been dropped in an upstream packaging gap.)

Solution

I've resolved my issue by updating /var/www/wallabag2/vendor/wallabag/php-mobi/MOBIClass/RecordFactory.php to conditionally define

if (!function_exists('mb_str_split')) {
    function mb_str_split($str, $length = 1) 
    {
        // ...
    }
}

Per https://stackoverflow.com/a/64303980/1020467

Clarified from my earlier comment.

@biosaat -- reopen if this doesn't work for you.