Problem/Motivation

The oEmbed resource fetcher is used to retrieve oembed data on-demand by things like field formatters. It does this by making a GET request to the resolved oEmbed resource url:

    try {
      $response = $this->httpClient->get($url);
    }
    catch (RequestException $e) {
      throw new ResourceException('Could not retrieve the oEmbed resource.', $url, [], $e);
    }

No connection timeout is passed to Guzzle, so it will default to what's set in \Drupal\Core\Http\ClientFactory's default initialization of 30 seconds.

If you have a site with a cold cache entry for an oembed resource, and the resource service is down and hanging all connections, you could easily swamp your own site as PHP gets tied up waiting 30 seconds every time someone is trying to view this resource. Especially true if you have multiple embeds from the same service on a single page and/or that page is very popular.

Something similar has happened on sites I've maintained in the past and it's not fun to deal with.

Proposed resolution

Ideally, Drupal would never request the oembed resource as a result of a visitor viewing the site, but that probably expands the scope of this issue too far. In the short term, I think it makes sense to set this value to 5 seconds, and perhaps make it configurable. I don't think an oembed service provided should reasonably take more than 5 seconds and timing out after that mount dramatically reduces the impact of that service being down.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3202145

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bkosborne created an issue. See original summary.

kuldeep_mehra27’s picture

Assigned: Unassigned » kuldeep_mehra27
kuldeep_mehra27’s picture

kuldeep_mehra27’s picture

Assigned: kuldeep_mehra27 » Unassigned
Status: Needs work » Needs review

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

phenaproxima made their first commit to this issue’s fork.

phenaproxima’s picture

Wrote tests and opened a new merge request targeting 9.3.x. I didn't open the 9.2.x one, so I can't close it, but we should close it so that committers can backport this patch at their discretion.

phenaproxima’s picture

Issue tags: +Needs follow-up

IMHO we should add configurability in a follow-up. The reason being that we'd need an update path to create the new config, and that will need its own test coverage, plus the need for ResourceFetcher to accept a new dependency (the config factory), which requires a deprecation...eurgh. Lots of overhead. Let's punt all that to a follow-up, and mitigate the issue at hand as quickly as possible.

phenaproxima’s picture

Issue tags: -Needs follow-up +Needs followup

Whoops, wrong tag.

Chris Burge’s picture

Status: Needs review » Reviewed & tested by the community

MR looks good. New unit test fails without updated code, so the test is valid. +1 for committing

  • catch committed b8abdeb on 9.3.x
    Issue #3202145 by kuldeep_mehra27, phenaproxima, bkosborne, Chris Burge...

  • catch committed e6f76d6 on 9.2.x
    Issue #3202145 by kuldeep_mehra27, phenaproxima, bkosborne, Chris Burge...
catch’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs followup

IMHO we should add configurability in a follow-up. The reason being that we'd need an update path to create the new config, and that will need its own test coverage, plus the need for ResourceFetcher to accept a new dependency (the config factory), which requires a deprecation...eurgh. Lots of overhead. Let's punt all that to a follow-up, and mitigate the issue at hand as quickly as possible.

I think we could make this a single, re-usable, $settings key, similar to $settings['entity_update_batch_size'].

Update module is another case where it shouldn't but theoretically can/does make outgoing http requests during a page request. Opened #3228350: Add a generic $settings timeout for outgoing http requests.

Committed/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!

xjm’s picture

I think the backport broke 9.2.x on Drupal\Tests\media\Unit\ResourceFetcherTest

E.g:
https://www.drupal.org/pift-ci-job/2150889

  • catch committed 96e7690 on 9.2.x
    Revert "Issue #3202145 by kuldeep_mehra27, phenaproxima, bkosborne,...
catch’s picture

Version: 9.2.x-dev » 9.3.x-dev

OK I think it is just a missing use statement in the test (for NullBackend), but moving back to 9.3.x and fixed having reverted from 9.2.x for now. If someone strongly feels this should be backported, please re-open with a backport patch/MR though.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.