Production workers 100% errors

Randomly started getting 500 errors in production env workers { "outcome": "exception", "scriptName": "mage-api", "diagnosticsChannelEvents": [], "exceptions": [ { "name": "Error", "message": "The script will never generate a response.", "timestamp": 1712089582194 } ],
J
James14d ago
Did you change anything? What does your worker do? Do you have a minimal reproduction?
GS
Gagan Suie14d ago
nothing was changed i've tried reverting to previous deployments and redeploying as well what do you mean minimal reproduction? to reproduce the error, just visit our website and any api trigered will give that response
GS
Gagan Suie14d ago
Mage - A collaborative streaming platform
Mage is a collaborative streaming platform for gamers and developers
J
James14d ago
I mean some code that others can run - a minimal example - to reproduce the issue There's not been any widespread reports I'm aware of, so likely going to require some debug and digging into where your worker is failing
GS
Gagan Suie13d ago
i finally figured out the error. it was related to packages. I reverted packages from a few days ago and its working now. Now i need to investigate which package was causing issues.......🙃 these are the working packages: "dependencies": { "@cloudflare/itty-router-openapi": "^1.0.6", "@miniflare/d1": "^2.14.1", "@tsndr/cloudflare-worker-jwt": "^2.2.1", "itty-router": "^4.0.11", "moment": "^2.29.4", "stripe": "^14.1.0", "tslib": "^2.5.0", "worker-auth-providers": "^0.0.13" }, "devDependencies": { "@cloudflare/workers-types": "^4.20240208.0", "@types/jest": "^29.5.0", "@typescript-eslint/eslint-plugin": "7.3.1", "@typescript-eslint/parser": "7.2.0", "esbuild": "^0.20.0", "eslint": "^8.37.0", "eslint-config-prettier": "^9.0.0", "eslint-config-typescript": "^3.0.0", "jest": "^29.5.0", "jest-environment-miniflare": "^2.13.0", "miniflare": "^3.0.0", "prettier": "3.2.5", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", "typescript": "^5.0.3", "wrangler": "^3.23.0" } and this version was causing errors: "dependencies": { "@cloudflare/itty-router-openapi": "^1.0.6", "@miniflare/d1": "^2.14.2", "@tsndr/cloudflare-worker-jwt": "^2.2.1", "itty-router": "^5.0.6", "moment": "^2.29.4", "stripe": "^14.1.0", "tslib": "^2.5.0", "worker-auth-providers": "^0.0.13" }, "devDependencies": { "@cloudflare/workers-types": "^4.20240329.0", "@types/jest": "^29.5.0", "@typescript-eslint/parser": "7.5.0", "@typescript-eslint/eslint-plugin": "7.5.0", "esbuild": "^0.20.0", "eslint": "^8.37.0", "eslint-config-prettier": "^9.0.0", "eslint-config-typescript": "^3.0.0", "jest": "^29.5.0", "jest-environment-miniflare": "^2.13.0", "miniflare": "^3.20240329.0", "prettier": "3.2.5", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", "typescript": "^5.0.3", "wrangler": "^3.44.0" }
J
James13d ago
I would guess itty-router since that's a major bump - did you check the breaking changes? Generally I'd recommend double checking this in future 🙂 Glad you figured it out though!
GS
Gagan Suie13d ago
you were right sir. great deduction! -i've never seen this error message and everything on google said it was an infinite loop issue on cloudflares side. And cloudflare had some outages today. Also a few people resolved the issue by reverting some random packages they had. -i did revert to previous deployments, but i guess i didn't go back far enough. -i have mergify and dependabot that automatically created and deployed new package versions (they dont deploy to production until i manually merge the changes). And i guess itty-router slipped under the radar this time!
J
James13d ago
Awesome to hear! You might want to spin up a few tests for your worker using the new vitest integration to catch these kind of things in those automation version bumps in future: https://blog.cloudflare.com/workers-vitest-integration If you're doing automatic dependency bumps, having some basic tests for if your worker still runs is something I would very strongly advise Even if it's just a smoke test that hits / - that would probably have caught this hanging issue from the version bump, and prevented the PR from merging 😄
GS
Gagan Suie13d ago
i will investigate this tonight thank you!
K
Kevin13d ago
I definitely recommend the v4 --> v5 Migration Guide: https://itty.dev/itty-router/migrations/v4-v5 But the biggest thing you have to do is to swap any .handle() references to .fetch(), as .handle() is now fully deprecated (v4 allowed both). Otherwise, when you ask for .handle() (no longer found), the Proxy catches it and assumes you're trying to register a route, not handle a request. Mayhem ensues. 🫠
Migration Guides > v4 to v5 - itty-router - itty.dev
Ultra-small, powerful helpers for modern serverless APIs.
GS
Gagan Suie13d ago
yep. that was the issue. im looking to actually migrate to @Cloudflare/itty-router-openapi but im having trouble restricting the /docs endpoint
K
Kevin13d ago
That one should be safe (they're still on v4). I'll be helping them get fully onto the new v5 stuff soon 🙂
GS
Gagan Suie13d ago
do you know if something like this is allowed? router.get('/docs', async () => await isAdmin(request, env))
K
Kevin13d ago
it depends on what's in isAdmin 🙂 (also, no need for the async/await in there)
GS
Gagan Suie13d ago
isAdmin returns true if user is an admin false otherwise
K
Kevin13d ago
assuming isAdmin is something like this:
const isAdmin = ({ headers }) => {
if (headers.get('Authorization') !== 'foo') {
throw new StatusError(401, 'Not Authorized')

// alernatively
return error(401)
}

// no return here allows further handlers
}
const isAdmin = ({ headers }) => {
if (headers.get('Authorization') !== 'foo') {
throw new StatusError(401, 'Not Authorized')

// alernatively
return error(401)
}

// no return here allows further handlers
}
yeah that's the prob... in itty, any handler that returns anything, stops the flow and responds (with whatever that was). The exception is explicitly returning undefined (that's allowed). So instead, you want it to not return anything to pass onto the next handlers/routes, or return (or throw) to break out early. It's an inversion on the express patterns, where you specifically had to allow next handlers to pass. Allows for typically far simpler/shorter handler code, but requires some rethinking (and has some gotchas)
GS
Gagan Suie13d ago
the isAdmin middlware code doesn't even hit const router = OpenAPIRouter() router.get('/docs', () => isAdmin(request, env))
K
Kevin13d ago
If you're trying to cover an entire branch, don't forget the wildcard. that route will only match /docs, not /docs/foo
router.get('/docs/*', isAdmin)
router.get('/docs/*', isAdmin)
GS
Gagan Suie13d ago
the swaggerui dashboard is still visible. but now /docs is appearing in swaggerui and when i try to execute it, i get unauthorized.
K
Kevin13d ago
// where is the request, env coming from here?
router.get('/docs', () => isAdmin(request, env))

// here isAdmin naturally has access to the request, env, etc passed from router.fetch
router.get('/docs', isAdmin)
// where is the request, env coming from here?
router.get('/docs', () => isAdmin(request, env))

// here isAdmin naturally has access to the request, env, etc passed from router.fetch
router.get('/docs', isAdmin)
have a repo for me to take a look at?
GS
Gagan Suie13d ago
the frontend is opensource, the backend is not unfortunately
GS
Gagan Suie13d ago
but you can watch my live stream on this very platform: https://mage.stream/channel/18
Mage - A collaborative streaming platform
Mage is a collaborative streaming platform for gamers and developers
GS
Gagan Suie13d ago
can you see my stream?
K
Kevin13d ago
I can
GS
Gagan Suie13d ago
brilliant!
K
Kevin13d ago
was just logging in ok, to put your own upstream catch before OpenAPI:
import { Router, error } from 'itty-router'
import { OpenAPIRouter } from '@cloudflare/itty-router-openapi'

const rootRouter = Router()
const router = OpenAPIRouter()

// example middleware
const isAdmin = (request) => {
if (!request.headers.get('Authorization')) {
return error(401)
}
}

rootRouter
// we register the auth catch on the root router
.all('/docs/*', isAdmin)

// then attach the next router to handle all requests
.all('*', router.fetch)

export default {
fetch: router.fetch
}
import { Router, error } from 'itty-router'
import { OpenAPIRouter } from '@cloudflare/itty-router-openapi'

const rootRouter = Router()
const router = OpenAPIRouter()

// example middleware
const isAdmin = (request) => {
if (!request.headers.get('Authorization')) {
return error(401)
}
}

rootRouter
// we register the auth catch on the root router
.all('/docs/*', isAdmin)

// then attach the next router to handle all requests
.all('*', router.fetch)

export default {
fetch: router.fetch
}
GS
Gagan Suie13d ago
that didn't work either. i learned how to handle it properly via their parameters: const router: any = OpenAPIRouter({ docs_url: env.ENV === 'local' ? '/docs' : 'null', redoc_url: env.ENV === 'local' ? '/redocs' : 'null' }) i was sending empty string. but it required a null string.
K
Kevin13d ago
oh super weird...
GS
Gagan Suie13d ago
hey thanks again for helping me remove a lot of fluff from the routes!
K
Kevin13d ago
Happy to help!
Want results from more Discord servers?
Add your server
More Posts
Can Cloudflare Pages be deployed under a domain Route?We’d like to use cloudflare pages for a single-page application but without having pages take over tNot able to uplod file on cloudinary.How can i upload files to Cloudinary in the Hono app? Everything is sorted but i am not able to get Production IssueI have made a small change in code in GitHub, But it's only being updated in my aliase domain given axum/examples/tracing-aka-logging/src/ma...Thanks. I'm trying to get this working combined with the tracing example in the axum repo https://gi`wrangler tail` with WebSocketsIs this not true for any incoming Websocket requests? - I have a console log inside of the `websockeenv variables are empty - HonoHello can you help me with some small example how to work locally with env variables? I tried c.env.I will check that out. Thank you! Do youI will check that out. Thank you! Do you mind me asking what tech stack you use? Do you try to use a522 ErrorHi all, I tried updating the CNAME from '@' to 'www.' so I can so more dynamic stuff with multi-repwrangler preview output is not the same as liveHello all, finally I got my astro project buildable. Using `wrangler pages dev ./dist` my website lWhat headers come back?I have one question. If I use Azure and I move to ai gateway will I still be able to receive the heaMultiple Set-Cookie headers folded into one headerIn the documentation (https://developers.cloudflare.com/workers/runtime-apis/headers/), it says thatCloudflare Tunnel routing through wrong locationsI have a tunnel that I use as an alternative to opening ports on my local network, however, there isRegister DomainHi. I cant pay for new .com domain. I can't figure out what could be the problem. The bank side saysCloudflare icons and stencils for diagramming.Do we have an open source repository with Cloudflare-specific icons?"Pro" plan, but can't see the Caching page.Hi there, I've subscribed to the "Pro" plan, but it seems I don't have access to the "Caching - Ovecan you provide an url for mp3?can you provide an url for mp3?Downloading data before building pages (SSG/SSR)I have the use case that I'm experimenting building a Cloudflare Pages project using Astro. It willJust the domain is neededJust the domain is neededRequest failed with status code 408 (Request Timeout)Failed upload sourcemap for [dist/assets/SecondaryButton-e.js.map]: Request failed with status code opened a PR to allow native web_sysopened a PR to allow native web_sys request, without having to ditch the event macro: https://github