Make WordPress Core

Opened 15 months ago

Last modified 4 months ago

#63764 assigned defect (bug)

ImageMagick writeImage() causes duplicate inotify events during thumbnail generation

Reported by: agiabanis Owned by:
Priority: normal Milestone: Awaiting Review
Component: Media Version: 6.8.2
Severity: normal Keywords: has-patch reporter-feedback
Cc: Focuses:

Description

When WordPress generates image thumbnails using ImageMagick, the writeImage() method in wp-includes/class-wp-image-editor-imagick.php causes duplicate CLOSE_WRITE,CLOSE inotify events.
Steps to reproduce:

  1. Upload an image to WordPress
  2. Monitor inotify events: inotifywait -m -e close_write /wp-content/uploads/
  3. Observe duplicate events for each thumbnail

Expected behavior:
One CLOSE_WRITE,CLOSE event per thumbnail file

Actual behavior:
Two CLOSE_WRITE,CLOSE events per thumbnail file

Root cause:
The writeImage() method performs internal buffering that creates two file operations:

  1. Write data to buffer
  2. Flush buffer to file

Proposed fix:
Replace writeImage() with getImageBlob() + file_put_contents() for single operation.

Files affected:

  • wp-includes/class-wp-image-editor-imagick.php (line 976)

Attachments (1)

fix-imagick-duplicate-events.patch​ (1.7 KB ) - added by agiabanis 15 months ago.

Download all attachments as: .zip

Change History (3)

This ticket was mentioned in ​PR #9342 on ​WordPress/wordpress-develop by ​@agiabanis.


15 months ago
#1

Fixes duplicate CLOSE_WRITE,CLOSE events during thumbnail generation by replacing ImageMagick's writeImage() method with a combination of getImageBlob() and file_put_contents() for single file operation.

This eliminates the internal buffering that causes two file operations:

  1. Write data to buffer
  2. Flush buffer to file

Benefits:

  • Eliminates duplicate inotify events
  • Reduces file I/O operations
  • Improves performance for thumbnail generation
  • Maintains full compatibility with all ImageMagick versions

#2 @nickchomey
4 months ago

  • Keywords reporter-feedback added

I cant replicate this. First, inotifywait -m -e close_write /wp-content/uploads doesnt show anything at all. But if I navigate to wp-content/uploads/2026/06 and run inotifywait -m -e close_write . it shows this

./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-scaled.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-300x200.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-1024x683.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-150x150.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-768x512.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-1536x1024.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-2048x1365.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-624x416.jpg

I suspect this is a server/OS issue... Can you share details about your environment? Site Health has lots to share: ​https://[YOURSITE.COM]/wp-admin/site-health.php

Note: See TracTickets for help on using tickets.