neenhouse (chris)
neenhouse (chris)
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
I also raised a support ticket to look at this issue, in case its something specific to our account
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
request/response objects are passed around to make logging properties of those objects convienent, but nothing is reading / consuming requests for the sake of these requests, just reading headers.
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
Typically, in the additional outgoing requests, the function signature passed to ctx.waitUntil is pretty consistent, it's an async function that returns await fetch(...) so that the promise returned to waitUntil is from the fetch function
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
In the above issue- const response = await fetchOrigin(request, env); this response is the one that is truncated. It's going to be the first outbound subrequest from the worker
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
Top Level Handler:
import {Env, fetchOrigin} from './src';
import {sendCustomResponseMetric} from './metrics';

/**
* handleFetch()
* Primary handler for processing worker request
* @param request {Request} - CF worker request class
* @param env {Env} - CF worker environment
* @param ctx {ExecutionContext} CF worker eecution context
* @returns {Promise<Response>} - Response object
*/

export async function handleFetch(
_request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
// Clone request object to allow modification
const request = new Request(_request);

// Use regular handler
const response = await fetchOrigin(request, env);

// Submit a metric for monitoring response status
if (isHtmlRequest(request)) {
ctx.waitUntil(sendCustomResponseMetric(request, response, env));
}

return response;
}
import {Env, fetchOrigin} from './src';
import {sendCustomResponseMetric} from './metrics';

/**
* handleFetch()
* Primary handler for processing worker request
* @param request {Request} - CF worker request class
* @param env {Env} - CF worker environment
* @param ctx {ExecutionContext} CF worker eecution context
* @returns {Promise<Response>} - Response object
*/

export async function handleFetch(
_request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
// Clone request object to allow modification
const request = new Request(_request);

// Use regular handler
const response = await fetchOrigin(request, env);

// Submit a metric for monitoring response status
if (isHtmlRequest(request)) {
ctx.waitUntil(sendCustomResponseMetric(request, response, env));
}

return response;
}
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
Top level entry:
import {
isHtmlRequest,
logger,
logToAnalytics,
logServiceRequest,
performanceNow,
} from 'shared-utils/src';

import {handleFetch} from './handler';
import {Env} from './src';

export const worker = {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
// Grab start time
env.fetchStartTime = performanceNow();

// Initialize subRequest counter
env.subRequests = 0;

// Enable passthrough on exception
// ctx.passThroughOnException();

// Get response
const response = handleFetch(request, env, ctx);

// Responsd to client
return response
.then((resp: Response) => {
logServiceRequest(request, resp, env, ctx);
logger(env).log(`Subrequests: ${env.subRequests}`);
return response;
})
.catch((e) => {
// Log error locally
const WORKER_NAME = env.WORKER_NAME;
const DEPLOY_ENV = env.DEPLOY_ENV;
logger(env).error(e, {WORKER_NAME, DEPLOY_ENV});

// Only log exceptions related to HTML requests to limit logs sent to Analytics
if (isHtmlRequest(request)) {
const message = `${(e as Error).message}`;
const stack = (e as Error).stack;

// Logs to analytics, non-blocking
ctx.waitUntil(logToAnalytics({level: 'ERROR', message, stack}, {request, env}));
}

// Return response
return response;
});
},
};

export default worker;
import {
isHtmlRequest,
logger,
logToAnalytics,
logServiceRequest,
performanceNow,
} from 'shared-utils/src';

import {handleFetch} from './handler';
import {Env} from './src';

export const worker = {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
// Grab start time
env.fetchStartTime = performanceNow();

// Initialize subRequest counter
env.subRequests = 0;

// Enable passthrough on exception
// ctx.passThroughOnException();

// Get response
const response = handleFetch(request, env, ctx);

// Responsd to client
return response
.then((resp: Response) => {
logServiceRequest(request, resp, env, ctx);
logger(env).log(`Subrequests: ${env.subRequests}`);
return response;
})
.catch((e) => {
// Log error locally
const WORKER_NAME = env.WORKER_NAME;
const DEPLOY_ENV = env.DEPLOY_ENV;
logger(env).error(e, {WORKER_NAME, DEPLOY_ENV});

// Only log exceptions related to HTML requests to limit logs sent to Analytics
if (isHtmlRequest(request)) {
const message = `${(e as Error).message}`;
const stack = (e as Error).stack;

// Logs to analytics, non-blocking
ctx.waitUntil(logToAnalytics({level: 'ERROR', message, stack}, {request, env}));
}

// Return response
return response;
});
},
};

export default worker;
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
No description
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
I should mention that when this behavior happens, it totally breaks the HTML page we are serving (we putting workers in front of nextJS applications)
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 5/7/2025 in #workers-help
responseStreamDisconnected errors when making 6+ sub requests in worker
This all happens in actually happens in less than 1 second. I've attached a CF log (with some fields redacted)
12 replies
CDCloudflare Developers
Created by neenhouse (chris) on 10/15/2024 in #general-help
logpush + workers
One more question- do you expect the RayID from the worker trace log to match the RayID in the parent access log record?
10 replies
CDCloudflare Developers
Created by neenhouse (chris) on 10/15/2024 in #general-help
logpush + workers
Thank you!
10 replies
CDCloudflare Developers
Created by neenhouse (chris) on 10/15/2024 in #general-help
logpush + workers
So, I'll end up with 3 events total, 2 access log events (parent, sub request) and one worker trace log event (which I opted my worker into).
10 replies
CDCloudflare Developers
Created by neenhouse (chris) on 10/15/2024 in #general-help
logpush + workers
Yes- do they also have 1 other event for the parent request?
10 replies
CDCloudflare Developers
Created by neenhouse (chris) on 12/14/2023 in #r2
Question about serving JS and CSS assets
1 replies