[Serve] Fix Java long poll timeout serialization#61875
Conversation
Fix a bug in Serve long polling where the Python-to-Java long poll path could raise on normal timeout. LongPollHost.listen_for_change() can legally return LongPollState.TIME_OUT when no updates arrive before the timeout window. The Java bridge method listen_for_change_java() was forwarding that result directly into protobuf serialization, but _listen_result_to_proto_bytes() assumes it always receives a mapping and unconditionally calls .items(). As a result, a normal long poll timeout on the Java path could fail the controller RPC instead of returning an empty update set. Signed-off-by: weimingdiit <weimingdiit@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request addresses a bug in the Java long poll mechanism where a timeout would lead to a serialization failure. The fix involves correctly handling the LongPollState.TIME_OUT case by converting it to an empty dictionary, which prevents the error and aligns with the expected behavior of returning an empty result on timeout. A new test case has been added to verify this fix, ensuring that timeouts are handled gracefully. The changes are logical, well-implemented, and properly tested.
|
Hi @abrarsheikh @simon-mo when you have a chance, could you take a look at this PR? |
|
Hi @bveeramani, When you get a chance, could you take another look at this PR? |
|
@harshit-anyscale @abrarsheikh Thanks for your review and merge! |
## Description Fixes a bug in LongPollHost.listen_for_change_java() when the upstream listen_for_change() call times out. listen_for_change() can return LongPollState.TIME_OUT, but the Java wrapper path previously forwarded that value directly to _listen_result_to_proto_bytes(), which expects a dictionary of updated objects. This could cause the Java long-poll path to fail on timeout. This PR converts LongPollState.TIME_OUT to an empty result before serialization, so Java callers receive a valid empty LongPollResult instead. ## Related issues ray-project#61874 ## Additional information Added a unit test to verify that listen_for_change_java() returns an empty LongPollResult on timeout. Signed-off-by: weimingdiit <weimingdiit@gmail.com>
Description
Fixes a bug in LongPollHost.listen_for_change_java() when the upstream listen_for_change() call times out.
listen_for_change() can return LongPollState.TIME_OUT, but the Java wrapper path previously forwarded that value directly to _listen_result_to_proto_bytes(), which expects a dictionary of updated objects. This could cause the Java long-poll path to fail on timeout.
This PR converts LongPollState.TIME_OUT to an empty result before serialization, so Java callers receive a valid empty LongPollResult instead.
Related issues
#61874
Additional information
Added a unit test to verify that listen_for_change_java() returns an empty LongPollResult on timeout.