Download & Extend

HTTP_REQUEST_TIMEOUT constant value is not negative

Project:Drupal core
Version:8.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:needs backport to D7

Issue Summary

All URI, networking, and communication errors are using negative, 0, or NULL status codes.

In various locations, drupal_http_request() ensures this by negating a potential status code:

<?php
   
// When a network error occurs, we use a negative number so it does not
    // clash with the HTTP status codes.
   
$result->code = -$errno;
?>

This was consistent until #156582: drupal_http_request() should support timeout setting came, which added:

<?php
/**
* Error code indicating that the request made by drupal_http_request() exceeded
* the specified timeout.
*/
define('HTTP_REQUEST_TIMEOUT', 1);
?>

and directly returns:

<?php
 
if ($info['timed_out']) {
   
$result->code = HTTP_REQUEST_TIMEOUT;
   
$result->error = 'request timed out';
    return
$result;
  }
?>

All application-level error handling logic that previously checked for

  // Catch 0, NULL, and any negative status code (networking errors).
  if ($response->code <= 0) exit;

now has to additionally check for the custom Drupalism and non-existing status code 1.

AttachmentSizeStatusTest resultOperations
drupal.http-timeout.0.patch449 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 33,646 pass(es).View details

Comments

#1

Status:active» needs review

#2

Status:needs review» reviewed & tested by the community

#3

Committed to 8.x and 7.x. For 6.x we need to adjust #156582: drupal_http_request() should support timeout setting.

#4

Status:reviewed & tested by the community» fixed

#5

Doesn't this collide with the $errno returned by fsockopen() ?

#6

Status:fixed» closed (fixed)

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