Support » Plugin: Media Sync » Import fails with 503 Service Unavailable

  • Resolved padc

    (@padc)


    I am trying to scan a large image library to import its media to my WordPress database. The can returns all files as expected.

    If I choose to import all missing files, the process aborts after a few seconds with this error:

    [Media Sync] [AJAX error] error E: Service Unavailable

    Looking at the console, I see a POST error:
    503 (Service Unavailable)

    I have found that I can import media files from scan results if I choose fewer than 10 files at a time, and this does not always work.

    I have set the server and WP memory to 256M, and increased the PHP.ini max_execution_time to 300.

    Any advice appreciated as it will take ages to import all files in batches of 10 or less.

    Is there a way to throttle requests so the server doesn’t reject them?

Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Contributor Simon Kane

    (@simonkane)

    Aborting in “a few seconds” is very unusual.
    How long do your batches take to run?
    When I run 10 (which is pretty much my max, too), it takes on the order of 3-5 minutes. I am on the very top tier of GoDaddy shared hosting, and have very little traffic (it’s a specialty B2B eCommerce site).

    Thread Starter padc

    (@padc)

    OK, so in another test of 15 files, it failed after around 90 seconds.

    Here’s a screen cap: https://share.nim.bz/RBuEmj10

    Plugin Contributor Simon Kane

    (@simonkane)

    OK – I see a couple of things here.
    First, on my system, the “0 of 15” increments as each file is processed. Now, I haven’t used this plugin for a while — maybe that behavior has been changed. But also, I have found that even on fails, the files that were completed are still there. Is that what you see?

    Also, a 503 is normally a CDN-to-server issue. Are you running a CDN?
    This is especially pertinent because you said you raised exec time to 5 minutes (which is more typically a minimum starting point for any server). If it were a server problem, it shouldn’t timeout in 90 seconds — and yet, the server is issuing the fail message, so I’m a bit lost as to what’s happening under the covers.

    To wildly speculate, I think something else is going on — why would this plugin be issuing a REST call to something (which may be the source of the 503)??

    What other plugins on your server might have involvement? Feel free to post a copy of your WP status report.

    Does this plugin upload files of any kind? If not, why do big files fail?

    Shouldn’t this plugin just list files and update the database?

    I’m having the same problem here mentions. The memory used is 512Mb.

    How can I help?`

    Plugin Contributor Simon Kane

    (@simonkane)

    “why do big files fail?”
    It has to do with what WordPress is doing under the covers –
    such as all the processing it takes to resize and save multiple image sizes.

    Thread Starter padc

    (@padc)

    Hi @simonkane,

    There is no CDN involvement as this is still a development site. It is hosted on Litespeed, so I have disabled all of its caching too. This has no impact.

    I am inclined to think it is some server issue that is blocking requests, so I may reach out to my hosting company. I was hoping the plugin develepor may be able to shed some light before I raise a ticket though.

    Plugin Author erolsk8

    (@erolsk8)

    Hey @padc,

    That’s quite strange behaviour. Because this plugin makes many requests in the background to process selected files (in batches) to avoid potential timeouts when importing a lot of files at once.

    So it would be cool if you could inspect the page and see what’s going on in the background. So you’d need to open browser’s DevTools (Option + ⌘ + J [mac] / Shift + CTRL + J [win]), Network tab, click on failed batch and on the right side find “Preview”. Or maybe there is something in Console tab.

    I can’t think of anything else that wasn’t mentioned already. But I’ll try to take a closer look on Monday. I didn’t have time to work on this plugin in a while, so I’ll test it with the latest WordPress version, maybe something has changed. Which WP version are you using?

    Thanks

    Erol

    Plugin Author erolsk8

    (@erolsk8)

    Hi @lsobral,

    That’s right, this plugin doesn’t upload/move or edit the actual files, it only scans to find their name and path (in which directory they are). And during the import, it only updates the database. It uses same functions that WordPress uses for Media Library. So I also doubt that file size matter. Maybe if there are some other plugins or themes which “detect” a file upload and then want to do some additional action.

    Sorry I didn’t really help much, but it’s quite hard to guess why it’s failing. Maybe you can also check Network tab in browser’s dev tools.

    Erol

    Plugin Author erolsk8

    (@erolsk8)

    I just pushed a new version 1.2.6 which changes the response of each imported batch when debugging is turned on. So it will show import status (success or failed with found errors) for each imported file directly in UI. That would hopefully catch the error and show it in UI, so there should be no need to inspect the page, go to Network tab, and all of that I mentioned in previous comments.

    I also tested it with WordPress 5.8.2, but I couldn’t replicate the errors described here.

    I really hope this will help with debugging 🤞

    Plugin Contributor Simon Kane

    (@simonkane)

    Great!

    What triggers debug mode (if it’s in the plugin, I don’t ee it)?
    Just WP_DEBUG setting?

    Thread Starter padc

    (@padc)

    @erolsk8 Thanks for your efforts on this. Sadly, still not useful information (that I can see).

    I made a video of what’s happening (with the latest version – 1.2.6): https://share.nim.bz/o0u79qNm

    Plugin Contributor Simon Kane

    (@simonkane)

    I’m wondering why you don’t seem to have the “Dry Run” checkbox?
    It should be in between “import selected” and the date/time options.

    And, just to be sure, have you tried running it with the Storefront theme and minimal active plugins? Some themes and plugins will have an effect on REST/AJAX.

    Thread Starter padc

    (@padc)

    @simonkane The “Dry Run” checkbox is not there because I turned it off in the plugin settings: https://share.nim.bz/DOu6lWk9

    We are using a custom theme we are developing, so I doubt it’s that. However, I’ll try it with a default theme and no other plugins enabled.

    Thread Starter padc

    (@padc)

    One other thought that may have an impact…

    The old site (from where the media originated) has Settings > Media > Organize my uploads into month- and year-based folders checked, whereas the new (dev) site does not.

    This means all media to be imported is within year > month folders, and existing media is just loose in the Uploads folder.

    Don’t know if this has a bearing on things??

    Plugin Contributor Simon Kane

    (@simonkane)

    Thanks much!
    I went and looked on the plugins page for a “settings” link,
    and not seeing it, I quit looking.
    Totally forgot about WP settings (it’s a WooCommerce site).

    Anyway, to follow along, I got a WP error (red) message with just 5 files:
    “[Media Sync] [AJAX error] parsererror E: SyntaxError: Unexpected token < in JSON at position 0”

    The 3 debug messages I see all have to do with the “UI” eg (“table-render”), and they are A-OK.

    Not seeing any 503. Am running current WP, Woo (Storefront theme), and Media Sync.
    Last thing I see looks good, and the first file is imported.

    Response 200, and nice HTML — which is not visible on the browser-rendered page.

    /wp-admin/admin-ajax.php?mediaSyncBatch=1&_fs_blog_admin=true
    <div class='media-sync-html-response-item-success'>✅ media-sync-item-ast-shipping-providers_7-eleven-png</div>

    Here’s the parsed POST form-data (request).

    action: media_sync_import_files
    security: ee19f888e5
    dry_run: false
    file_post_date: default
    media_items[0][file]: /home/.../wp-content/uploads/ast-shipping-providers/7-eleven.png
    media_items[0][row_id]: media-sync-item-ast-shipping-providers_7-eleven-png

    `

    However, the other files in the batch are not touched.
    Not seeing any JSON in the network log at all.

    ** Could it be that an error in delivering the response HTML is the problem?
    Expecting JSON but receiving just the OK HTML ??
    ** And then maybe my import fails to continue because of that error?
    ** But this could very well be a separate error than the 503.

Viewing 15 replies - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.