CurlDispatcher timeout should be caught and rather not crash the page

Created on 8 May 2023, over 1 year ago

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.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @AndersTwo
  • 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;
      }
  • πŸ‡¨πŸ‡¦Canada dustin@pi

    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.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    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?

Production build 0.71.5 2024