From 64ddebd9bd89f01a36436bf9c84f276fc18da676 Mon Sep 17 00:00:00 2001 From: Superskyyy Date: Fri, 4 Oct 2024 11:00:24 -0400 Subject: [PATCH 1/4] Add more nuanced checks for http proxy status errors Signed-off-by: Superskyyy --- python/ray/serve/_private/proxy.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/ray/serve/_private/proxy.py b/python/ray/serve/_private/proxy.py index ffb3edf06433..f3989f65a5ca 100644 --- a/python/ray/serve/_private/proxy.py +++ b/python/ray/serve/_private/proxy.py @@ -999,7 +999,7 @@ async def send_request_to_replica( status = ResponseStatus( code=status_code, # TODO(edoakes): we need a more nuanced check than this. - is_error=status_code != "200", + is_error=not status_code.startswith("2"), ) expecting_trailers = asgi_message.get("trailers", False) elif asgi_message["type"] == "websocket.accept": @@ -1021,10 +1021,19 @@ async def send_request_to_replica( if not asgi_message.get("more_trailers", False): response_generator.stop_checking_for_disconnect() elif asgi_message["type"] == "websocket.disconnect": + status_code = str(asgi_message["code"]) + + # Check based on standard WebSocket status codes + if status_code in ["1000", "1001"]: + # Normal closure or going away, no error + is_error = False + else: + # Other 1xxx codes are specified as errors + is_error = status_code.startswith("1") + status = ResponseStatus( - code=str(asgi_message["code"]), - # TODO(edoakes): we need a more nuanced check than this. - is_error=False, + code=status_code, + is_error=is_error ) response_generator.stop_checking_for_disconnect() From a38edf33109c969e05ddb4a89ff03b181b090348 Mon Sep 17 00:00:00 2001 From: Superskyyy Date: Fri, 4 Oct 2024 11:02:37 -0400 Subject: [PATCH 2/4] Remove TODO Signed-off-by: Superskyyy --- python/ray/serve/_private/proxy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/ray/serve/_private/proxy.py b/python/ray/serve/_private/proxy.py index f3989f65a5ca..016f150536f5 100644 --- a/python/ray/serve/_private/proxy.py +++ b/python/ray/serve/_private/proxy.py @@ -998,7 +998,6 @@ async def send_request_to_replica( status_code = str(asgi_message["status"]) status = ResponseStatus( code=status_code, - # TODO(edoakes): we need a more nuanced check than this. is_error=not status_code.startswith("2"), ) expecting_trailers = asgi_message.get("trailers", False) From be15344b8046a7e1fb3e6cf37530438b439fa6f7 Mon Sep 17 00:00:00 2001 From: Superskyyy Date: Fri, 4 Oct 2024 12:31:02 -0400 Subject: [PATCH 3/4] Fix up lint Signed-off-by: Superskyyy --- python/ray/serve/_private/proxy.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/python/ray/serve/_private/proxy.py b/python/ray/serve/_private/proxy.py index 4bd09a405157..a669b102ec48 100644 --- a/python/ray/serve/_private/proxy.py +++ b/python/ray/serve/_private/proxy.py @@ -1022,19 +1022,16 @@ async def send_request_to_replica( response_generator.stop_checking_for_disconnect() elif asgi_message["type"] == "websocket.disconnect": status_code = str(asgi_message["code"]) - + # Check based on standard WebSocket status codes if status_code in ["1000", "1001"]: # Normal closure or going away, no error - is_error = False + is_error = False else: # Other 1xxx codes are specified as errors is_error = status_code.startswith("1") - - status = ResponseStatus( - code=status_code, - is_error=is_error - ) + + status = ResponseStatus(code=status_code, mis_error=is_error) response_generator.stop_checking_for_disconnect() yield asgi_message From 5c9fd9a29bbb39ffd25d4e922fe1bf96867b699b Mon Sep 17 00:00:00 2001 From: Superskyyy Date: Fri, 4 Oct 2024 16:14:26 -0400 Subject: [PATCH 4/4] Update python/ray/serve/_private/proxy.py Fixup Co-authored-by: Edward Oakes Signed-off-by: Superskyyy --- python/ray/serve/_private/proxy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/serve/_private/proxy.py b/python/ray/serve/_private/proxy.py index a669b102ec48..6e0efb2e9e00 100644 --- a/python/ray/serve/_private/proxy.py +++ b/python/ray/serve/_private/proxy.py @@ -1031,7 +1031,7 @@ async def send_request_to_replica( # Other 1xxx codes are specified as errors is_error = status_code.startswith("1") - status = ResponseStatus(code=status_code, mis_error=is_error) + status = ResponseStatus(code=status_code, is_error=is_error) response_generator.stop_checking_for_disconnect() yield asgi_message