• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / pg_net / 16278604114

14 Jul 2025 09:46PM UTC coverage: 92.495% (-0.2%) from 92.683%
16278604114

push

github

steve-chavez
test: fix error message for new curl version

493 of 533 relevant lines covered (92.5%)

211.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/errors.c
1
#include "pg_prelude.h"
2
#include "curl_prelude.h"
3
#include "errors.h"
4

5
/*
6
 * Show a more detailed error message when a timeout happens, which includes the DNS, TCP/SSL handshake and HTTP request/response time. An example message is like:
7
 *
8
 * "Timeout of 800 ms reached. Total time: 801.159000 ms (DNS time: 73.407000 ms, TCP/SSL handshake time: 677.256000 ms, HTTP Request/Respose time: 50.103000 ms)"
9
 *
10
 * Curl allows to calculate the above by applying substractions on some internal timings. Refer to https://blog.cloudflare.com/a-question-of-timing/ for an explanation of these timings.
11
 *
12
 * There are extra considerations:
13
 *
14
 * - If a step (e.g. TCP handshake [CURLINFO_CONNECT_TIME]) surpasses the request timeout, its given timing is 0.
15
 *   However the step duration can still be determined by using the total time (CURLINFO_TOTAL_TIME).
16
 *   We want to show at which step the timeout occurred.
17
 *
18
 * - If a step is omitted its given timing is 0. This can happen on non-HTTPS requests with the SSL handshake time (CURLINFO_APPCONNECT_TIME).
19
 *
20
 * - The pretransfer time (CURLINFO_PRETRANSFER_TIME) is greater than 0 when the HTTP request step starts.
21
 */
22
curl_timeout_msg detailed_timeout_strerror(CURL *ez_handle, int32 timeout_milliseconds){
52✔
23
  double namelookup;    EREPORT_CURL_GETINFO(ez_handle, CURLINFO_NAMELOOKUP_TIME,    &namelookup);
52✔
24
  double appconnect;    EREPORT_CURL_GETINFO(ez_handle, CURLINFO_APPCONNECT_TIME,    &appconnect);
52✔
25
  double connect;       EREPORT_CURL_GETINFO(ez_handle, CURLINFO_CONNECT_TIME,       &connect);
52✔
26
  double pretransfer;   EREPORT_CURL_GETINFO(ez_handle, CURLINFO_PRETRANSFER_TIME,   &pretransfer);
52✔
27
  double starttransfer; EREPORT_CURL_GETINFO(ez_handle, CURLINFO_STARTTRANSFER_TIME, &starttransfer);
52✔
28
  double total;         EREPORT_CURL_GETINFO(ez_handle, CURLINFO_TOTAL_TIME,         &total);
52✔
29

30
  elog(DEBUG2, "The curl timings are time_namelookup: %f, time_connect: %f, time_appconnect: %f, time_pretransfer: %f, time_starttransfer: %f, time_total: %f",
52✔
31
      namelookup, connect, appconnect, pretransfer, starttransfer, total);
32

33
  // Steps at which the request timed out
34
  bool timedout_at_dns       = namelookup == 0 && connect == 0; // if DNS time is 0 and no TCP occurred, it timed out at the DNS step
52✔
35
  bool timedout_at_handshake = pretransfer == 0; // pretransfer determines if the HTTP step started, if 0 no HTTP ocurred and thus the timeout occurred at TCP or SSL handshake step
52✔
36
  bool timedout_at_http      = pretransfer > 0; // The HTTP step did start and the timeout occurred here
52✔
37

38
  // Calculate the steps times
39
  double _dns_time =
104✔
40
    timedout_at_dns ?
41
      total: // get the total since namelookup will be 0 because of the timeout
52✔
42
    timedout_at_handshake ?
43
      namelookup:
52✔
44
    timedout_at_http ?
45
      namelookup:
52✔
46
    0;
47

48
  double _handshake_time =
×
49
    timedout_at_dns ?
50
      0:
51
    timedout_at_handshake ?
52
      total - namelookup: // connect or appconnect will be 0 because of the timeout, get the total - DNS step time
52✔
53
    timedout_at_http ?
54
      (connect - namelookup) +                    // TCP handshake time
52✔
55
      (appconnect > 0 ? (appconnect - connect): 0): // SSL handshake time. Prevent a negative here which can happen when no SSL is involved (plain HTTP request) and appconnect is 0
52✔
56
    0;
57

58
  double _http_time =
104✔
59
    timedout_at_dns ?
60
      0:
52✔
61
    timedout_at_handshake ?
62
      0:
52✔
63
    timedout_at_http ?
64
      total - pretransfer:
52✔
65
    0;
66

67
  // convert seconds to milliseconds
68
  double dns_time_ms       = _dns_time       * 1000;
52✔
69
  double handshake_time_ms = _handshake_time * 1000;
52✔
70
  double http_time_ms      = _http_time      * 1000;
52✔
71
  double total_time_ms     = total           * 1000;
52✔
72

73
  // build the error message
74
  curl_timeout_msg result = {.msg = {}};
52✔
75
  snprintf(result.msg, CURL_TIMEOUT_MSG_SIZE,
52✔
76
    "Timeout of %d ms reached. Total time: %f ms (DNS time: %f ms, TCP/SSL handshake time: %f ms, HTTP Request/Response time: %f ms)",
77
    timeout_milliseconds, total_time_ms, dns_time_ms, handshake_time_ms, http_time_ms
78
  );
79
  return result;
52✔
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc