Skip to content

Commit 73dae42

Browse files
committed
RPC: Fix Python get_object_from_java missing END_OF_OBJECT on batch boundary
When serialized data items are an exact multiple of the handler's batchSize, END_OF_OBJECT ends up alone in a separate batch that receiver.receive() never pulls. Drain the pending batch after receive() completes — analogous to Java/JS's explicit q.take(). Add integration test with small batchSize to exercise the fix.
1 parent 2ed9e10 commit 73dae42

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • rewrite-python/rewrite/src/rewrite/rpc

rewrite-python/rewrite/src/rewrite/rpc/server.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,21 @@ def pull_batch() -> List[Dict[str, Any]]:
196196
# Receive and deserialize the object (applies diffs to before state)
197197
try:
198198
obj = receiver.receive(before, q)
199+
200+
# After receive() completes, END_OF_OBJECT may still be pending in a
201+
# separate batch (happens when data items are an exact multiple of the
202+
# handler's batchSize). Drain it — analogous to Java's explicit
203+
# q.take() after receive().
204+
if not received_end:
205+
pull_batch()
206+
if not received_end:
207+
raise RuntimeError(f"Did not receive END_OF_OBJECT marker for object {obj_id}")
199208
except Exception:
200209
# Reset our tracking of the remote state so the next interaction
201210
# forces a full object sync (ADD) instead of a delta (CHANGE).
202211
remote_objects.pop(obj_id, None)
203212
raise
204213

205-
# Verify we received the complete object (END_OF_OBJECT was in the final batch)
206-
# This matches Java's RewriteRpc.java line 474-475 which explicitly checks for END_OF_OBJECT
207-
if not received_end:
208-
raise RuntimeError(f"Did not receive END_OF_OBJECT marker for object {obj_id}")
209-
210214
if obj is not None:
211215
# Update our understanding of what Java has
212216
remote_objects[obj_id] = obj

0 commit comments

Comments
 (0)