Repository navigation
Conversation
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
6f43be5 to
19c9891
Compare
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
stefanvanburen
left a comment
There was a problem hiding this comment.
Took a pass against the RFC in connectrpc/connectrpc.com#452 — the websocket conformance suites at 63de2c4 pass for me locally on uvicorn, pyvoy, and pyvoy-trio (442/442 each), but a few things slip past them, inline. None of them are blocking IMO (the origin ones all fail closed), so approving; fine to fix here or follow up, whichever's easier.
Couple of RFC SHOULDs that I don't think need to block this, but ought to at least get a docs note: without connect-timeout-ms the wait for the client's M is unbounded (§11.2 wants a server deadline), and no_context_takeover (§10) is entirely up to the ASGI server's config, so I think users need to be told to set it (like server.py does for pyvoy / uvicorn).
| self._compressions = resolve_compressions(compressions) | ||
| codecs = codecs if codecs is not None else get_default_codecs() | ||
| self._codecs = {codec.name(): codec for codec in codecs} | ||
| for pattern in websockets_allowed_origins: |
There was a problem hiding this comment.
websockets_allowed_origins is iterated twice here, so a generator validates fine and then ends up as ():
app = HaberdasherASGIApplication(svc, websockets_allowed_origins=(o for o in ["app.example.org"]))
assert app._websockets_allowed_origins == () # every cross-origin handshake then 403sProbably just want to tuple(...) it once up front.
| self._compressions = resolve_compressions(compressions) | ||
| codecs = codecs if codecs is not None else get_default_codecs() | ||
| self._codecs = {codec.name(): codec for codec in codecs} | ||
| for pattern in websockets_allowed_origins: |
There was a problem hiding this comment.
Also, I imagine folks will copy their CORS origins over here — "https://app.example.org" passes validation, but _origin_allowed only compares the authority so it can never match, and every handshake from that origin gets a 403. Maybe reject patterns containing :// (or /) with the same ValueError?
There was a problem hiding this comment.
When looking at starlette's docs, I didn't think people generally include scheme. A validation error for it seems to make sense anyways though
| value = value_bytes.decode() | ||
| if name in ("content-type", CONNECT_STREAMING_HEADER_COMPRESSION): | ||
| continue | ||
| if name.startswith("trailer-"): |
There was a problem hiding this comment.
This stashes trailer-* headers on every response, but they only get sent back out in _send_error_end, so on a 200 they're just dropped. e.g. a handler setting ctx.response_headers["trailer-id"] = "x" on MakeHat gives ['M{}', 'B{"size":10}', 'S{}']. Admittedly an edge case (and trailer- is already ambiguous for Connect unary), but I think it should only strip them when _error_status is set?
| # RPCs also use the streaming message flow. | ||
| if ( | ||
| isinstance(endpoint, EndpointUnary) | ||
| and not is_websocket |
There was a problem hiding this comment.
On trio, routing unary through _call_stream means the disconnect watch only sets the flag (the asyncio watch always cancels), so a unary handler blocked on something slow runs to completion after the client goes away — in a quick test with a 2s sleep and a 1001 disconnect, the handler ran the full 2s on trio, cancelled immediately on asyncio. Same as gRPC unary on trio today I think, so not new, but §8 does say the server MUST treat it as cancelled. Maybe pass cancel=True to the watch when the endpoint is unary?
| def _stream_error( | ||
| state: _StreamState, close_code: int, code: Code, message: str | ||
| ) -> ConnectError: | ||
| state.close_code = close_code |
There was a problem hiding this comment.
Setting close_code here, when the error is created rather than when it ends the RPC, means a client-stream / bidi handler that catches the request error and returns normally still gets a 1009 (or 1002 / 1003) close after a successful S{}. Repro: MakeFlexibleHat that does try: async for _ in request: ... except ConnectError: pass, read_max_bytes=8, and an oversized B → S{} then close 1009. §13 only has those codes after an S carrying the error, so I think the send adapter ought to only use the override close code when the S actually has an error.
Yup I think we'll want to add these to Deployment in the connectrpc.com docs |
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
47286c6 to
50a4198
Compare
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
…nto websockets-asgi # Conflicts: # conformance/test/gen/connectrpc/conformance/v1/service_connect.py # connectrpc-grpchealth/connectrpc_grpchealth/_gen/grpc/health/v1/health_connect.py # connectrpc-grpcreflect/connectrpc_grpcreflect/_gen/grpc/reflection/v1/reflection_connect.py # connectrpc-grpcreflect/connectrpc_grpcreflect/_gen/grpc/reflection/v1alpha/reflection_connect.py # connectrpc-grpcreflect/test/connectrpc/example/deprecated_connect.py # connectrpc-grpcreflect/test/connectrpc/example/empty_connect.py # connectrpc-grpcreflect/test/connectrpc/example/haberdasher_connect.py # example/example/gen/connectrpc/eliza/v1/eliza_connect.py # protoc-gen-connectrpc/protoc_gen_connectrpc/__init__.py # src/connectrpc/_protocol_connect.py # src/connectrpc/_protocol_grpc.py # src/connectrpc/_server_async.py # test/connectrpc/example/deprecated_connect.py # test/connectrpc/example/empty_connect.py # test/connectrpc/example/haberdasher_connect.py # test/google_compat/connectrpc/example/deprecated_connect.py # test/google_compat/connectrpc/example/empty_connect.py # test/google_compat/connectrpc/example/haberdasher_connect.py # test/test_server_protocols.py
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
|
Pending conformance bump |
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
This implements the pending spec for websockets support in the ASGI server. It takes an approach of wrapping the websockets stream into the normal connect one, while we can consider an abstraction to use a more websockets-native control flow, I feel the wrapping approach works pretty well already.
connectrpc/connectrpc.com#452