Skip to content

Commit

Permalink
fix: ensure we honor first-byte-timeout and between-bytes-timeout for…
Browse files Browse the repository at this point in the history
… dynamically registered backends (#719)
  • Loading branch information
JakeChampion committed Jan 18, 2024
1 parent 3b03a72 commit 2851507
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
28 changes: 28 additions & 0 deletions integration-tests/js-compute/fixtures/app/src/dynamic-backend.js
@@ -1,3 +1,4 @@
/// <reference path="../../../../../types/index.d.ts" />
import { Backend } from 'fastly:backend';
import { CacheOverride } from 'fastly:cache-override';
import { allowDynamicBackends } from "fastly:experimental";
Expand All @@ -6,6 +7,33 @@ import { isRunningLocally, routes } from "./routes.js";

/// The backend name is already in use.

routes.set("/backend/timeout", async () => {
if (isRunningLocally()) {
return pass('ok')
}
allowDynamicBackends(true);
let backend = new Backend(
{
name: 'httpme1',
target: 'http-me.glitch.me',
hostOverride: "http-me.glitch.me",
useSSL: true,
dontPool: true,
betweenBytesTimeout: 1_000,
connectTimeout: 1_000,
firstByteTimeout: 1_000
}
);
console.time(`fetch('https://http-me.glitch.me/test?wait=5000'`)
let error = await assertRejects(() => fetch('https://http-me.glitch.me/test?wait=5000', {
backend,
cacheOverride: new CacheOverride("pass"),
}));
console.timeEnd(`fetch('https://http-me.glitch.me/test?wait=5000'`)
if (error) { return error }
return pass('ok')
});


// implicit dynamic backend
{
Expand Down
11 changes: 11 additions & 0 deletions integration-tests/js-compute/fixtures/app/tests.json
Expand Up @@ -2131,6 +2131,17 @@
"body": "ok"
}
},
"GET /backend/timeout": {
"environments": ["compute"],
"downstream_request": {
"method": "GET",
"pathname": "/backend/timeout"
},
"downstream_response": {
"status": 200,
"body": "ok"
}
},
"GET /implicit-dynamic-backend/dynamic-backends-disabled": {
"environments": ["viceroy"],
"downstream_request": {
Expand Down
Expand Up @@ -496,17 +496,23 @@ bool fastly_compute_at_edge_http_req_register_dynamic_backend(
fastly_compute_at_edge_types_error_t *err) {
uint32_t backend_config_mask = 0;

if (config->use_ssl.is_some && config->use_ssl.val) {
backend_config_mask |= BACKEND_CONFIG_USE_SSL;
}
if (config->dont_pool.is_some && config->dont_pool.val) {
backend_config_mask |= BACKEND_CONFIG_DONT_POOL;
}
if (config->host_override.is_some) {
backend_config_mask |= BACKEND_CONFIG_HOST_OVERRIDE;
}
if (config->connect_timeout.is_some) {
backend_config_mask |= BACKEND_CONFIG_CONNECT_TIMEOUT;
}
if (config->use_ssl.is_some && config->use_ssl.val) {
backend_config_mask |= BACKEND_CONFIG_USE_SSL;
if (config->first_byte_timeout.is_some) {
backend_config_mask |= BACKEND_CONFIG_FIRST_BYTE_TIMEOUT;
}
if (config->dont_pool.is_some && config->dont_pool.val) {
backend_config_mask |= BACKEND_CONFIG_DONT_POOL;
if (config->between_bytes_timeout.is_some) {
backend_config_mask |= BACKEND_CONFIG_BETWEEN_BYTES_TIMEOUT;
}
if (config->ssl_min_version.is_some) {
backend_config_mask |= BACKEND_CONFIG_SSL_MIN_VERSION;
Expand Down

0 comments on commit 2851507

Please sign in to comment.