aelvan/Imager-Craft

409 conflict error when replacing a file with the same name on S3 & Imgix

zizther opened this issue · 7 comments

I don't know if this issue is directly to do with Imager, but wanted to check before looking into other areas.

I have contacted Imgix, they replied with
Unfortunately, we don't have much information on how to resolve the 409 with AWS S3, as the error is being generated outside of our service.

I am trying to upload files with the same file name to an S3 bucket, I get the notification to say if I should replace or copy the image. Every time I select replace an alert box show saying Client error: POST https://api.imgix.com/v2/... resulted in a 409 conflict. Response Duplicate request pending where the operation is already happening, this stop files with the same filename being over written and the file ends up getting the timestamp appended instead.

This issue also happens when trying to purge images too.
The error is Client error: POST https://api.imgix.com/v2/image/purger resulted in a 490 conflict. Response: Duplicate purge request pending

All files are stored on AWS S3 with the Cloudfront details included.

I am running:
Craft v3.2.8
Imager v2.1.10

@aelvan Any ideas why this could be happening, not sure if this is something directly to do with Imager, how Craft deals with purging assets or Imgix

This happens when you try to replace files in Craft?

@aelvan HI. Sorry for the delay in responding.

This issue happens when looking to replace a file with the same filename.
I have imgixEnableAutoPurging set to true, i don't know if this send a request, and when you want to overwrite a file it causes the issue?

If you set imgixEnableAutoPurging to false, does the error go away?

Can you provide a stacktrace that shows where the error is thrown?

Doing some tests.

With imgixEnableAutoPurging set to true I am not able to upload a file with the same filename, when I select 'Replace it' in the Craft modal, it says the duplicate purge pending issue then proceeds to upload the image with the current timestamp appended to the name.
I am also unable to perform the Purge from Imgix when selecting it from the dropdown in the Assets section of the CP. The same duplicate purging error shows.

When I set imgixEnableAutoPurging to false I am unable to perform a Purge from Imgix, the same error shows.
However I am able to upload a file with the same filename and it work correctly, it does not show any errors and replaces the file.


In this case, all assets are hosted on AWS S3, with Cloudfront for those assets not controlled via Imgix.
I have completed the AWS config with the cloudfront settings in the imager.php file, but have the transformer set to 'imgix'

Right, so that was a weird one.

I was only able to reproduce this by duplicating the command self::$plugin->imgix->purgeAssetFromImgix($event->asset); in the event listener in Imager.php. Which leads me to believe that the underlying issue is that you have some other misbehaving plugin install, that results in Imager being initialized more that once. It's a common mistake, rendering templates or similar in a plugin's init method could cause it. A Craft weak-spot in my opinion.

Anyways, I was able to fix this by not throwing the error generated by the guzzle client when doing the purge. The error will still be logged, but it doesn't make sense to continue throwing that error for a task like this.

The fix will be in the next tagged release.

Appreciate you looking into this one man!