Requests to worker getting canceled when trying to...
# workers-help
a
I have a Worker deployed that handles redirections for users based on their experiment grouping for an A/B test. The Worker handles 4 cases: * If the user has an existing analytics cookie, and the user is in: - the control group - the variant group * If the user has no analytics cookie yet (i.e. is a new user), and the user is in: - the variant group - the control group For the variant group cases, the worker redirects users to the experimental URL:
Copy code
const statusCode = 302
const resp = new Response(null, {
  status: statusCode,
  headers: new Headers({ Location: EXPERIMENTATION_URL }),
  })
return resp
For the control group, we send the user through to the original site they requested:
Copy code
let resp = await fetch(request)
resp = new Response(resp.body, resp)
resp.headers.append("Set-Cookie", newCookie) // only if they have no cookie yet
return resp
However, for some reason, in about 50% of the cases that we hit the case where the user has no analytics cookie yet, and is in the control group, the request in the Worker logs shows up as canceled. A few seconds after the canceled request, there is usually a successful request, which seems to be a retry, but this results in the user being assigned to a variant group. This case is the last case to get handled in the Worker code. However, I am a bit baffled as this is the only case that fails. Is there any way to check why these requests are being canceled? Or are there any common reasons why requests get canceled, especially if the requests only get canceled in a specific code path ?