Skip to content

fix(rust): retry join_loro with an empty version on VersionUnknown - #69

Open
petralithic wants to merge 1 commit into
loro-dev:mainfrom
petralithic:fix/join-loro-version-unknown
Open

petralithic wants to merge 1 commit into
loro-dev:mainfrom
petralithic:fix/join-loro-version-unknown

Conversation

@petralithic

Copy link
Copy Markdown

Summary

LoroWebsocketClient::join_loro fails as soon as the receiver answers JoinError(VersionUnknown). join_with_adaptor and the TS client both rejoin with an empty version in that case. So a plain Loro doc cannot rejoin a receiver that no longer recognizes its version, for example after the receiver pruned or reset its history, while the same doc joined through LoroDocAdaptor can.

This change makes join_loro resend the JoinRequest once with an empty version when it gets VersionUnknown. If the empty version is also rejected, the join fails as before. Other join errors are unchanged, and so is the wire format.

This covers the first half of #16. It does not pass receiver_version to get_alternative_version, because that would change the public CrdtDocAdaptor trait. Sending the receiver's own version back as the join version would also be wrong: the receiver would then skip history the client is missing. I'm happy to follow up if you want a specific API for that.

Tests

New rust/loro-websocket-client/tests/join_version_unknown.rs runs a small in-process WebSocket receiver:

  • It rejects the client's version with VersionUnknown, then accepts an empty version and sends its history. The join succeeds and the server text is imported next to the local edit. This test fails on main with join error: VersionUnknown.
  • It rejects every version. The client sends exactly two joins (its version, then an empty one) and returns an error. On main it sends only one.

cargo test --workspace in rust/ passes. cargo clippy -p loro-websocket-client --all-targets reports nothing in the changed code. I ran rustfmt only on the new test file, because cargo fmt --check already reports diffs on main in untouched files.

This is independent of #67 and #68: it only touches join_loro.

join_loro returned an error as soon as the receiver answered VersionUnknown, so a plain Loro doc could not rejoin a receiver that no longer recognises its version. Rejoin once with an empty version, as join_with_adaptor and the TS client already do.

Refs loro-dev#16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant