brett
09/17/2021, 11:53 AMfetch(url, {method: "POST", body: "foo"})
definitely worksbrett
09/17/2021, 11:54 AMjohn.spurlock
09/17/2021, 12:05 PMray_232_air
09/17/2021, 12:06 PMaa
09/17/2021, 11:35 PMJames
09/17/2021, 11:53 PMAbortController
with fetch
or something I'd imagine?ItsWendell
09/17/2021, 11:54 PMaa
09/18/2021, 12:00 AMaa
09/18/2021, 12:00 AMkenton
09/18/2021, 1:12 AMkenton
09/18/2021, 1:14 AMaa
09/18/2021, 5:47 PMreadyState
property. It is undefined. Similarly the constants WebSocket.{CONNECTED, CONNECTING, etc}
are undefined. This was causing our code to close the connection early.
We did not notice this because the typescript type we are using (from https://github.com/cloudflare/workers-types/issues/84#issuecomment-813114157) uses interface WebSocket
which adds the method accept()
to the built-in DOM WebSocket
type. The DOM type does have readyState
so typescript didn't complain, it just failed at runtime.
If CF can't completely implement the spec, it would be helpful to publish and maintain your own types, as otherwise this kind of thing is very confusing to debug.kenton
09/18/2021, 7:31 PMreadyState
is not that useful because by the time you obtain a WebSocket
using our APIs, it's always already in the OPEN
state. But we should fill out the API with all the standard methods and properties nevertheless.aa
09/18/2021, 7:39 PMworker.send()
ever throw between accept()
and onclose
? I remove the worker from the active set in onclose
but i'm worried about it transitioning to a closed state or some other not-ready state without that event firing. That's why I was checking the readyState
property before calling send()
.kenton
09/18/2021, 7:45 PMaccept()
hasn't been called
* if close()
has already been called
* if onerror
has fired.
Otherwise, it adds the message to a send queue, which shouldn't ever throw. (I say "shouldn't" because saying "it will never throw" is like saying "there are no bugs".)aa
09/18/2021, 7:46 PMkenton
09/18/2021, 7:46 PMkenton
09/18/2021, 7:46 PMsend()
doesn't care if onclose
has occurred since they represent opposite directions of the stream. onerror
is what matters.aa
09/18/2021, 7:48 PMaa
09/18/2021, 7:49 PMkenton
09/18/2021, 7:53 PMHardAtWork
09/20/2021, 6:20 AMdmitry.centro
09/20/2021, 8:24 AMItsWendell
09/20/2021, 10:29 AMkenton
09/20/2021, 3:02 PMkenton
09/20/2021, 3:03 PMHardAtWork
09/20/2021, 3:04 PMkenton
09/20/2021, 3:11 PMHardAtWork
09/20/2021, 3:12 PMWallacy
09/20/2021, 3:19 PM