- Issue created by @silverham
- π¦πΊAustralia silverham
Patch based on running
FTPExtension->connect() ;
once. - Status changed to Needs review
over 1 year ago 7:57am 28 February 2023 - π«π·France andypost
+++ b/core/lib/Drupal/Core/FileTransfer/FTPExtension.php @@ -11,6 +11,10 @@ class FTPExtension extends FTP implements ChmodInterface { + // Ensure `$this->connect()` is only called once. + if ($this->setConnectRunState()) { +++ b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php @@ -62,6 +62,13 @@ abstract class FileTransfer { + private $hasConnectRunState = FALSE; @@ -439,6 +452,19 @@ public function setChroot() { + public function setConnectRunState() { + $hasConnectRunState = $this->hasConnectRunState; + $this->hasConnectRunState = TRUE; + return $hasConnectRunState; +++ b/core/lib/Drupal/Core/FileTransfer/SSH.php @@ -22,6 +22,10 @@ public function __construct($jail, $username, $password, $hostname = "localhost" + // Ensure `$this->connect()` is only called once. + if ($this->setConnectRunState()) {
I think there's
$connectionHandle
private variable which could be used instead - π¦πΊAustralia silverham
Interesting, I see that
ftp_connect()
andssh2_connect()
both return a non-NULL value, so FALSE or a resource object so anisset()
check could work. I can redo patch later, or feel free to do yourself if you get to it first, no worries. - π¦πΊAustralia silverham
Updated patch to use a do a null check as per suggested :
isset($this->connection)
.Didn't use
isset($this->connectionHandle)
in subclass is it is private (no subclass access to parent) and all sub-classes still use naming convention of$this->connection
- Status changed to Needs work
over 1 year ago 9:13pm 13 March 2023 - πΊπΈUnited States smustgrave
This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue under control, following Review a patch or merge request β as a guide.
Next step would be to add a test case to show the issue.
Hi,
As one of the few remaining users who can't use composer, I was somewhat interested in getting this fixed.
So if I gave you a working solution, would anybody be willing to implement it?What I did was (in FileTransfer.php)
- Kept the added property declarations but renamed connection back (removed -Handle) and made it public
- Added code to make sure chrootHandle is always set when needed (that part broke with the addition of the declaration) and fixed some leftover uses of just chroot (without 'Path')
Im adding adding this as a .zip file, I know that's not the right way but learning how to create a merge request seems like a lot of work...
Btw, I tested this on a site with shared hosting with a chrroted FTP. I also verified that the 'Local' subclass still works.
Some more Details on what I dit, and why:
The change made with Drupal 9.5 was to add property declarations for $connection, $croot and $jail.
connection and chroot were also renamed and made private respectively protected.
Some more 'magic' were function added, probably to make it (unit tests?) work again.Renaming connection was imho ill-advised. Because that means the __get() has two different things to do: providing access from the outside and the FTPExension subclass, and connecting when $connection is absent in the class itself.That just leads to unnecessary complications.
By the way, connection is deliberatley unset in core\modules\update\update.authorize.inc
See "unset($filetransfer->connection);" (with an explanation added)So what happens is: From the form where the ftp credentials are entered, a connection is established, but probably just to test it.
When we come back wih a task, connection is therefore completely gone. Also, chrootPath has somehow lost it's value.
But because it is declared, it is null, not absent. So while connection reestablishes itself, the 'magic' __get is nottriggered by it. Apparently, null is not unaccessible for the sake of this.So I had to find a location where to call setChroot() and found it in fixRemotePath().
After that, all the other magic functions were no longer needed.
- π¬π§United Kingdom SoulReceiver
The latest patch works wonderfully. Tested in Drupal 10.2.5, it fixed the issue for me with the SSH library. Beforehand I was too was getting that undefined `connection` property, but this patch resolves that and eliminates the recursive behaviour that would lead to an infinite loop if the exception weren't being thrown.
- Status changed to RTBC
7 months ago 10:51am 2 May 2024 - π¬π§United Kingdom longwave UK
Unsure how we can add a test for this, this class doesn't have any existing test coverage and without the ssh2 extension or an FTP server to connect to I'm not sure what value any test would have.
The fix and explanation make sense to me, the additional comments in this (untested) code are welcome too, going to mark this as RTBC. Although it does also point to the fact that very few people probably use this if it's been broken since 9.5...
- First commit to issue fork.
- Status changed to Needs work
7 months ago 2:27pm 3 May 2024 - π¬π§United Kingdom alexpott πͺπΊπ
This is testable and the change in #3295821: Ignore: patch testing issue for PHP 8.2 attributes β was implemented incorrectly. We can fix this without changing the logic of things that extend \Drupal\Core\FileTransfer\FileTransfer. In fact the changes to \Drupal\Tests\system\Functional\FileTransfer\TestFileTransfer in #3295821: Ignore: patch testing issue for PHP 8.2 attributes β should have warned us that we were doing this wrong.
- Status changed to Needs review
7 months ago 2:31pm 3 May 2024 - Status changed to Needs work
7 months ago 1:48pm 7 May 2024 - πΊπΈUnited States smustgrave
Appears to have a test failure
1) Drupal\Tests\system\Functional\FileTransfer\FileTransferTest::testJail Error: Call to a member function run() on null /builds/project/drupal/core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php:62 /builds/project/drupal/core/lib/Drupal/Core/FileTransfer/FileTransfer.php:216 /builds/project/drupal/core/lib/Drupal/Core/FileTransfer/FileTransfer.php:335 /builds/project/drupal/core/lib/Drupal/Core/FileTransfer/FileTransfer.php:180 /builds/project/drupal/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php:95 /builds/project/drupal/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
- Status changed to Needs review
7 months ago 2:31pm 7 May 2024 - Status changed to RTBC
7 months ago 2:48pm 7 May 2024 - πΊπΈUnited States smustgrave
Hiding patches for clarity
Tests are all green so switch to chroot and connection didn't break anything.
Not sure how else to test but seems fine to me.
- π¬π§United Kingdom alexpott πͺπΊπ
Added a comment that shows we have coverage of the problem in the issue summary by reverting a change to the test code that was made in the earlier issue.
Also the test only job fails as expected - https://git.drupalcode.org/project/drupal/-/jobs/1534956
- First commit to issue fork.
- Status changed to Needs work
6 months ago 11:45pm 19 May 2024 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
This one needs a reroll for phpstan baseline folks. Thanks
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
kim.pepper β made their first commit to this issueβs fork.
- Status changed to Needs review
6 months ago 11:57pm 19 May 2024 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Rebased on 11.x
- Status changed to RTBC
6 months ago 9:07am 20 May 2024 - π¬π§United Kingdom alexpott πͺπΊπ
I thought we could remove the
#[\AllowDynamicProperties]
because we had the@property
tags - it's good enough for PHPStan but not for PHP itself... so we still need that attribute.Setting back to rtbc because @kim.pepper's fix was only phpstan and comments.
-
larowlan β
committed bf153748 on 10.3.x
Issue #3344877 by alexpott, silverham: [regression] FTPExtension class...
-
larowlan β
committed bf153748 on 10.3.x
-
larowlan β
committed 4e04b15a on 10.4.x
Issue #3344877 by alexpott, silverham: [regression] FTPExtension class...
-
larowlan β
committed 4e04b15a on 10.4.x
-
larowlan β
committed 3843b614 on 11.0.x
Issue #3344877 by alexpott, silverham: [regression] FTPExtension class...
-
larowlan β
committed 3843b614 on 11.0.x
-
larowlan β
committed 6284267b on 11.x
Issue #3344877 by alexpott, silverham: [regression] FTPExtension class...
-
larowlan β
committed 6284267b on 11.x
- Status changed to Downport
6 months ago 9:31pm 28 May 2024 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Committed to 11.x, 11.0.x, 10.4.x and 10.3.x
Doesn't apply to 10.2.x - moving to there for a possible backport
- First commit to issue fork.
- Merge request !8298[regression] FTPExtension class can no longer connect as of 9.5.x β (Open) created by quietone
- Status changed to RTBC
6 months ago 10:43am 5 June 2024 - π¬π§United Kingdom longwave UK
Same changes locally; this should also fix the PHPStan fails in 10.2.x at https://git.drupalcode.org/project/drupal/-/pipelines/191534
- Status changed to Downport
6 months ago 10:51am 5 June 2024 - π³πΏNew Zealand quietone
That's a nice benefit. There were conflicts in the baseline so I rebuilt it.
- Status changed to RTBC
6 months ago 11:00am 5 June 2024 -
longwave β
committed c141f9e6 on 10.2.x
Issue #3344877 by alexpott, silverham, quietone: [regression]...
-
longwave β
committed c141f9e6 on 10.2.x
- Status changed to Fixed
6 months ago 5:48pm 5 June 2024 Automatically closed - issue fixed for 2 weeks with no activity.