craftcms / aws-s3

Amazon S3 volume type for Craft CMS.
https://plugins.craftcms.com/aws-s3
MIT License
61 stars 28 forks source link

Unable to 'refresh' buckets in asset volume setup #103

Closed Decipher-Webmaster closed 3 years ago

Decipher-Webmaster commented 3 years ago

When trying to set up a new asset volume with S3, we add the asset url, access key ID and secret access key to our .env file. We then reference these in the setup of the new volume and click 'refresh' to retrieve the S3 bucket list, but this ends up timing out and a 'Server error occurred' red warning flashing at the top of the page and a 500 internal server error occurs in the browser console.

There are no errors that get logged in 'storage/logs'.

When testing some of our existing sites that have S3 successfully set up with Craft, it appears that if I try to refresh the buckets within the settings page for any of the existing volumes, this also fails with the same message. Fortunately for these sites, they were set up before this issue arose. On the flip side, any new sites we're trying to set up with S3 storage just won't work.

Decipher-Webmaster commented 3 years ago

Here is the composer.json file:

{ "require": { "craftcms/aws-s3": "1.2.11", "craftcms/cms": "3.5.13.2", "fruitstudios/linkit": "1.1.11", "verbb/navigation": "1.4.1", "vlucas/phpdotenv": "^3.4.0" }, "require-dev": { "yiisoft/yii2-shell": "^2.0.3" }, "autoload": { "psr-4": { "modules\\": "modules/" } }, "config": { "sort-packages": true, "optimize-autoloader": true, "platform": { "php": "7.3" } }, "scripts": { "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ] } }

andris-sevcenko commented 3 years ago

Strange. Can you enable devMode, open up the developer console in your browser, open the console's network tab, and then try refreshing again? You should see an Ajax request pop up which tries to refresh the bucket list. Can you tell me the contents of the response to that request?

Decipher-Webmaster commented 3 years ago

@andris-sevcenko Yeah sure. There's no particularly useful response for this error though unfortunately, I'll paste it here anyway.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
 you@example.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

This was from a site we've already got setup and onto production so this S3 setup definitely worked in development at one point. But now none of the sites will refresh. I could perhaps try reverting back to a previous version?

andris-sevcenko commented 3 years ago

Hang on. That looks like a generic web server error, as opposed to the Craft-style one. This indicates, that Craft never got the request. Can you check the web server error logs?

Decipher-Webmaster commented 3 years ago

Here's the log from Apache:

[Wed Oct 21 09:45:17 2020] [error] [client ::1] FastCGI: comm with server "/Applications/MAMP/fcgi-bin/php7.3.1.fcgi" aborted: idle timeout (30 sec), referer: http://seacorislandlines.local/admin/settings/assets/volumes/10
[Wed Oct 21 09:45:17 2020] [error] [client ::1] FastCGI: incomplete headers (0 bytes) received from server "/Applications/MAMP/fcgi-bin/php7.3.1.fcgi", referer: http://seacorislandlines.local/admin/settings/assets/volumes/10
Decipher-Webmaster commented 3 years ago

Other AJAX requests from Craft work fine, it just seems to be this one that's become troublesome. Would it still suggest an issue with the plugin or perhaps something else?

andris-sevcenko commented 3 years ago

Here are a few things to try to narrow it down:

1) Try switching to a different PHP version in MAMP 2) If you are using Apache and MAMP, try using PHP as an Apache module, instead of FastCGI. 3) xDebug to see what's taking so long 4) If xDebug is not possible, add logging to file in vendor/craftcms/aws-s3/src/controllers/DefaultController.php

My gut feeling tells me that the request to the AWS servers is being blocked by a firewall or something and the request is left in limbo until FastCGI times out, but that hypothesis has to be validated first.

Are you seeing this on one hosting environment or are you seeing this change across different hosting environments? '

Decipher-Webmaster commented 3 years ago

Thanks for narrowing it down. I followed these steps but couldn't seem to overcome the issue. However, digging into MAMP's apache config a little more I then came across this article, https://craftcms.stackexchange.com/questions/4661/fastcgi-error-when-accessing-a-local-development-site-using-mamp-pro.

It seems that the default idle timeout is too low after messing with variations of the answer in the article to find out exactly what the issue is. I removed the timeout flag suggested in that article and it failed again, timeout's the issue!

Thanks for your help @andris-sevcenko it was a big help in finding the cause!