Problem/Motivation

A timeout exception with CurlDispatcher should be caught gracefully and inject some message into the text, rather than crashing the entire page. Here's an example stacktrace:

Embed\Http\NetworkException: Resolving timed out after 10000 milliseconds in Embed\Http\CurlDispatcher->error() (line 158 of vendor/embed/embed/src/Http/CurlDispatcher.php).
Embed\Http\CurlDispatcher->exec() (Line: 32)
Embed\Http\CurlDispatcher::fetch() (Line: 31)
Embed\Http\CurlClient->sendRequest() (Line: 56)
Embed\Http\Crawler->sendRequest() (Line: 24)
Embed\Embed->get() (Line: 65)
Drupal\url_embed\UrlEmbed->getEmbed() (Line: 141)
Drupal\url_embed\Plugin\Filter\ConvertUrlToEmbedFilter::Drupal\url_embed\Plugin\Filter\{closure}()
preg_replace_callback() (Line: 148)
Drupal\url_embed\Plugin\Filter\ConvertUrlToEmbedFilter::convertUrls() (Line: 43)
Drupal\url_embed\Plugin\Filter\ConvertUrlToEmbedFilter->process() (Line: 118)
Drupal\filter\Element\ProcessedText::preRenderText()
call_user_func_array() (Line: 101)

Steps to reproduce

Maybe temporarily block a provider with a firewall to provoke a timeout.

Proposed resolution

Catch exception and inject a message instead of the embedded medium.

Issue fork url_embed-3358830

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:

Comments

AndersTwo created an issue. See original summary.

AndersTwo’s picture

This particular exception happens when a YouTube video is no longer available or private, which is a very common situation.

The crash can be temporarily fixed in ConvertUrlToEmbedFilter.php as shown in the snippet below, although it's really only a first attempt at getting past the road block. Please excuse the misplaced use of a Bootstrap alert here. You certainly know a better way to inject a message to make end users aware of a problem with one of the URLs in the text.

 public function process($text, $langcode) {
    try {
      $result = new FilterProcessResult(static::convertUrls($text, $this->settings['url_prefix']));
    }
    catch (NetworkException $e) {
      $result = new FilterProcessResult('<p class="alert alert-danger">A network exception occurred with embedding an URL</p> ' . $text);
    }
    return $result;
  }
dustin@pi’s picture

Version: 2.0.0-alpha1 » 3.x-dev

Hitting a similar issue, a "Could not resolve Host" is causing the WSOD:

Embed\Http\NetworkException: Could not resolve host: ..... in Embed\Http\CurlDispatcher->error() (line 165 of /app/vendor/embed/embed/src/Http/CurlDispatcher.php).

The error is coming from the same location in the underlying Embed library.

mark_fullmer’s picture

I tested this on the 3.x branch and was unable to reproduce, using both a private YouTube video and a video that no longer exists. The report in #3 shows the expected line in embed/embed for version 4 of that library (which is the version that should be used), so I assume this *can* be reproduced with 3.0.0-beta1 of url_embed and v4.4.14 of embed/embed. Can someone provide more specific steps to reproduce?

mark_fullmer’s picture

Status: Active » Postponed (maintainer needs more info)

Setting to "Postponed" based on comment #4

caesius’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.09 KB

We were seeing this when URLs were referencing factfinder.census.gov since their servers time out instead of giving a proper HTTP error.

I've added a patch which fixes the WSOD and logs the URL that timed out.

Note that each timeout will add 10 seconds to the page load, and each URL seems to get processed twice. In our case we were referencing factfinder 3 times so the page took a full minute to load until we removed https:// from the start. The good news is that the long load only happens after a drupal cache clear; subsequent visits load the page normally.

caesius’s picture

StatusFileSize
new966 bytes

I inadvertently included custom patch context in the previous patch -- updated patch to apply cleanly against 3.x

I'll also be converting the patch to an MR.

mattdanger’s picture

patch works nicely for me

mark_fullmer’s picture

Status: Needs review » Fixed

Thanks for the clarification and updated patch. While I feel like it shouldn't necessarily be the responsibility of the module to catch a cURL timeout, this approach is practical and lightweight, so I'm comfortable adding it to the module code. Marking as "Fixed"!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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