fix(grpc): use context.abort() with proper status codes instead of in-band errors (#19972)
Signed-off-by: Chang Su <chang.s.su@oracle.com>
This commit is contained in:
21
python/sglang/srt/grpc/utils.py
Normal file
21
python/sglang/srt/grpc/utils.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""gRPC utility functions."""
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import grpc
|
||||
|
||||
_HTTP_TO_GRPC_CODE = {
|
||||
HTTPStatus.BAD_REQUEST: grpc.StatusCode.INVALID_ARGUMENT,
|
||||
HTTPStatus.SERVICE_UNAVAILABLE: grpc.StatusCode.UNAVAILABLE,
|
||||
HTTPStatus.INTERNAL_SERVER_ERROR: grpc.StatusCode.INTERNAL,
|
||||
}
|
||||
|
||||
|
||||
def abort_code_from_output(output: dict) -> grpc.StatusCode:
|
||||
"""Map a scheduler error output to the appropriate gRPC status code."""
|
||||
finish_reason = output.get("meta_info", {}).get("finish_reason")
|
||||
if isinstance(finish_reason, dict):
|
||||
status_code = finish_reason.get("status_code")
|
||||
if status_code is not None:
|
||||
return _HTTP_TO_GRPC_CODE.get(status_code, grpc.StatusCode.INTERNAL)
|
||||
return grpc.StatusCode.INTERNAL
|
||||
Reference in New Issue
Block a user