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

[5.1] Joomla Update: Improving error handling when writing files #41096

Merged
merged 5 commits into from
Dec 7, 2023

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented Jun 30, 2023

Summary of Changes

In several support channels we do encounter sites where the files are not consistently on one version of Joomla. It seems as if updating somehow aborted midway or for specific files. This PR is an effort to review the code and find possible reasons for this behavior.

While loop

The while loop in line 1530 is not necessary. PHP is strictly linear and thus there is nothing which could change the $zipData during the runtime of the loop. In a theoretical worst case, this could actually create an infinite loop. Instead a simple if should be enough here.

is_string($unzipData)

gzinflate() and bzdecompress() both return a string in case of success. In case of an error, the return value is either false or an integer. Up till now we are not checking for this. This could for example happen if the compressed data is somehow corrupted. So in case that we didn't get a string as $unzipData, we should abort here.

fwrite()

This is actually the place where shit most likely hits the fan. We are writing unverified data to the file pointer without checking the result and suppressing any errors. I'm actually guessing, that fwrite() would throw at least a notice if $unzipData was not a string (thus decompressing failed) and not write anything, resulting in the previous file not being updated, but which we are suppressing with the @.
We are also not checking if writing of the file somehow failed for other reasons (diskspace full, file pointer somehow corrupted, space rays...) So in this place we are now checking if fwrite() returns false and then throw an error.

Testing Instructions

I was unable to recreate the situations described above and wrote this PR based on code review. Thus I can't provide testing instructions. If someone has corrupted update files, I would be very gratefull if you could attach this to this PR.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@brianteeman
Copy link
Contributor

In my experience (and I had it multiple times today) this problem occurs when the installation doesn't 100% complete the install but the user thinks it has.

In a recent release we added a log of each sql file that is processed. But we still dont log the files AND we dont display anything to a user who does not get a 100% install.

These are what the last few lines of the log looks like currently.

2023-06-30T17:28:16+00:00	INFO 127.0.0.1	update	Ran query from file 4.3.2-2023-05-20. Query text: ALTER TABLE `#__user_mfa` ADD COLUMN `tries` int NOT NULL DEFAULT 0 ;.
2023-06-30T17:28:16+00:00	INFO 127.0.0.1	update	Ran query from file 4.3.2-2023-05-20. Query text: ALTER TABLE `#__user_mfa` ADD COLUMN `last_try` datetime ;.
2023-06-30T17:28:16+00:00	INFO 127.0.0.1	update	End of SQL updates.
2023-06-30T17:28:16+00:00	INFO 127.0.0.1	update	Deleting removed files and folders.
2023-06-30T17:28:19+00:00	INFO 127.0.0.1	update	Cleaning up after installation.
2023-06-30T17:28:19+00:00	INFO 127.0.0.1	update	Update to version 4.3.2 is complete.

Today I had an upgrade that at first seemed to fail but then a browser refresh made me think it was a success. However when I checked the log I could see that it finished just before the end of the sql section. So no files/folders were deleted.

How many people even know about this log file? How many basic users can even access this file?

My immediate idea would be to have a flag set when an update begins and that flag is only reset when the update is complete. If for any reason that flag has not been reset then a big red warning can be displayed.

@Hackwar
Copy link
Member Author

Hackwar commented Jun 30, 2023

@brianteeman I will look into that potential source of problems tomorrow. This PR however concentrates on writing the files to the disc, not on the later stages with deleting files and running SQL updates.

@Hackwar
Copy link
Member Author

Hackwar commented Jul 1, 2023

@brianteeman please see #41098

@richard67
Copy link
Member

The issue mentioned in @brianteeman 's comment above that updates might fail without the user getting notice of that has been tackled and in my opinion solved with PRs #41367 and #41690 .

@richard67
Copy link
Member

I have tested this item ✅ successfully on 0a668f2

I've reviewed the code changes and can confirm that they are correct. In addition, I've successfully tested that a normal update still works.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41096.

@HLeithner
Copy link
Member

as said in maintainers that makes more sense to be backported to 4.4 so more tests for 5.0.0beta2 could be made

@HLeithner HLeithner changed the base branch from 5.0-dev to 5.1-dev September 30, 2023 22:49
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.1-dev.

@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on 0a668f2


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41096.

@richard67
Copy link
Member

richard67 commented Nov 26, 2023

@viocassel How have you applied this PR for testing and on which Joomla version? I'm asking because the PR meanwhile has been rebased from 5.0-dev to 5.1-dev and it had conflicts which I just have solved. If you have tested with 5.0: Could you do a brief retest on 5.1-dev? Thanks in advance. I just see testing instructions say "code review", and the code hasn't really changed since your test, so I will restore the test result. No need to test again.

@richard67
Copy link
Member

I have tested this item ✅ successfully on c9f55bb

Code review.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41096.

@richard67 richard67 changed the title [5.0] Joomla Update: Improving error handling when writing files [5.1] Joomla Update: Improving error handling when writing files Nov 26, 2023
@richard67
Copy link
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41096.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Nov 26, 2023
@Razzo1987 Razzo1987 merged commit 47e0fae into joomla:5.1-dev Dec 7, 2023
2 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 7, 2023
@Razzo1987
Copy link
Contributor

Thanks you!

@Quy Quy added this to the Joomla! 5.1.0 milestone Dec 7, 2023
@Hackwar Hackwar deleted the 5.0-joomlaupdate-1 branch March 22, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants