Skip to content

Commit ad86b59

Browse files
authored
[core][state] Fix false alarm in get_logs when a server chunk splits into multiple client chunks (#51750)
Signed-off-by: kaihsun <kaihsun@anyscale.com>
1 parent 263021b commit ad86b59

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

python/ray/util/state/api.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,16 +1284,27 @@ def get_log(
12841284
raise RayStateApiException(r.text)
12851285
for bytes in r.iter_content(chunk_size=None):
12861286
bytes = bytearray(bytes)
1287-
# First byte 1 means success.
1288-
if bytes.startswith(b"1"):
1289-
bytes.pop(0)
1287+
# Note that each iteration of the loop doesn't always get
1288+
# the entire chunk yielded from the server side.
1289+
# That is, the first byte isn't always 0 or 1.
1290+
#
1291+
# 1. If a server chunk starting with b"0" is split into two client chunks,
1292+
# an error will be raised during iteration of the first client chunk.
1293+
#
1294+
# 2. If a client chunk starts with b"1" or any other bytes, it succeeds.
1295+
#
1296+
# TODO (kevin85421): We should consider not using the first byte as an
1297+
# indicator of success or failure. This seems to be an uncommon pattern,
1298+
# and it doesn't seem important for the client side.
1299+
if bytes.startswith(b"0"):
1300+
error_msg = bytes.decode("utf-8")
1301+
raise RayStateApiException(error_msg)
1302+
else:
1303+
if bytes.startswith(b"1"):
1304+
bytes.pop(0)
12901305
logs = bytes
12911306
if encoding is not None:
12921307
logs = bytes.decode(encoding=encoding, errors=errors)
1293-
else:
1294-
assert bytes.startswith(b"0")
1295-
error_msg = bytes.decode("utf-8")
1296-
raise RayStateApiException(error_msg)
12971308
yield logs
12981309

12991310

0 commit comments

Comments
 (0)