fix(media): prevent getimagesize loopback deadlocks on missing images - #1030
fix(media): prevent getimagesize loopback deadlocks on missing images#1030faisalahammad wants to merge 2 commits into
Conversation
|
Please use |
|
@faisalahammad please make sure there is 1 bug fix per PR. |
ddfd6cd to
e05fcca
Compare
|
Rebased on dev branch with single commit for issue #894 fix. Thank you! |
|
@faisalahammad there are some conflicts to solve |
- Check if image URL host is internal domain in Utility::is_internal_url() - Return false early in _detect_dimensions() when local file is missing for internal URLs - Eliminate loopback HTTP GET requests to web server on missing images Fixes litespeedtech#894
e05fcca to
0cf7fc2
Compare
|
I have rebased the branch cleanly on dev branch with 1 commit. The merge conflicts are resolved. |
|
@faisalahammad thank you! :) |
… method - Remove public Utility::is_internal_url() added in this PR - Move host check into private Media::_is_internal_url() - Reuse Utility::internal() and CDN::internal() for host matching - Keep loopback deadlock prevention for missing internal images - Keep Throwable catch to handle PHP 8 ValueError on empty source Addresses PR review feedback. Refs litespeedtech#894
|
Addressed reviewer feedback in b80438c:\n\n- The deadlock fix is the internal site/CDN host check before getimagesize(); is_internal_file() alone returns false when the internal file is missing, which is the deadlock case.\n- Removed the new public Utility::is_internal_url() method. Host matching now reuses Utility::internal() and CDN::internal() through a private Media helper.\n- Retained the \Throwable catch because PHP 8 can raise ValueError for an empty filename.\n\nManual testing confirmed. No inline review threads were available through the GitHub API, so this is posted as the PR-level response. |
Summary
Fix getimagesize() LSAPI deadlocks on missing image URLs. When image URLs belong to internal site or CDN host but the file is missing locally, prevent getimagesize() from making self-referencing HTTP loopback requests back to OpenLiteSpeed web server.
Fixes #894
Changes
Media (
src/media.cls.php)Before:
After:
Why: If
is_internal_file()returnsfalseon an internal URL because the image is missing on disk, checkingUtility::is_internal_url( $src )returnsfalseearly. This skipsgetimagesize()so PHP workers do not make HTTP loopback GET calls to the same web server.Utility (
src/utility.cls.php)Before:
// Only is_internal_file existed, which requires file to exist on local diskAfter:
Why: Checks if a URL host matches the internal site or internal CDN domain without checking file existence on disk.
Testing
Test 1: Missing Local Image URL
Result: Page loads immediately without delays or PHP getimagesize warnings in error log.
Test 2: Valid Local Image
Result: Width and height dimensions are calculated and injected from local filesystem path as expected.