Websocket subprotocol results in Error: The script will never generate a response
Websockets - sending subprotocols (auth token smuggling) results in Error: The script will never generate a response.
Client:
Hono:
- Fails right away at the upgrade with
Error: The script will never generate a response.
on the server.
- This only happens if I send a subprotocol such as "potato"
which automatically gets converted to the sec-websocket-protocol
header as it should. Curiously I can see the header in the console log.
- Also tried with hc, same issue.13 Replies
hey! i came across this, which might help: https://github.com/cloudflare/cloudflare-docs/pull/15014
try manually closing the ws server-side in a
close
event handlerThanks! Do you mean adding a
onClose
method tot he return of the upgradeWebSocket
handler? I have it (I just trimmed down the minimal example so it doesn't take up space) and I still have the issue.
Or do you mean something else?onClose
, closing the server: https://developers.cloudflare.com/workers/observability/errors/#cause-2-websocket-connections-that-are-never-closedYep, I have it. Everything works until I send a protocol (which I'm trying to use to authenticate the user since websockets don't support typical headers)
where is it? i don't see it
also, can you syntax highlight your snippets?
I've highlighted it above. It's the onClose from the docs - https://hono.dev/docs/helpers/websocket
from the docs i linked above:
where do you
server.close()
?Oh, do you mean on the frontend?
Here's my frontend implementation:
no, i mean the backend
please read the docs i sent you
i haven't worked w webhooks a ton, so i can't explain it any more clearly than cloudflare does
i just searched the error message you were seeing, and it took me to a section of the cloudflare docs that addresses that specific error message
I appreciate your help 🙌
The issue is I'm only using workers through hono and I don't really know how to surface any of the interals. I'm literally using the hono upgradeWebSocket hanlder on one of the routes of the hono app. I might fall back to just sending the token as a query param
The issue is I'm only using workers through hono and I don't really know how to surface any of the interals. I'm literally using the hono upgradeWebSocket hanlder on one of the routes of the hono app. I might fall back to just sending the token as a query param
i would expect this to work (server-side, in your upgrade options)
i assume that
upgradeWebSocket
is a fairly minimal wrapper
yeah, pretty much: https://github.com/honojs/hono/blob/65edaf277a2dd3bb47406379904996ffdd3563e5/src/adapter/cloudflare-workers/websocket.ts#L37Woah, thanks! I'll look into it!
the hono codebase is insanely accessible