exception Invalid_argument("Sync.pull_exn: Handshake got an error") when using Sync
Hello, I have the following code which raises an inscrutable error:
open Lwt.Syntax
module Store = Irmin_git_unix.FS.KV(Irmin.Contents.String)
module Info = Irmin_unix.Info(Store.Info)
module Sync = Irmin.Sync.Make(Store)
module Config = struct
let root = "/tmp/irmin/test"
let init () =
let _ = Sys.command (Printf.sprintf "rm -rf %s" root) in
let _ = Sys.command (Printf.sprintf "mkdir -p %s" root) in
Irmin.Backend.Watch.set_listen_dir_hook Irmin_watcher.hook
end
let main_branch config =
let* repo = Store.Repo.v config in
Store.main repo
let main () =
Config.init();
let config = Irmin_git.config Config.root in
let* repo = Store.Repo.v config in
let* upstream = Store.remote "https://git.sr.ht/~jonsterling/public-trees" in
let* t = main_branch config in
let* _ = Sync.pull_exn t upstream `Set in
let+ list = Store.list t [] in
list |>
List.iter (fun (_, store_tree) ->
match Store.Tree.destruct store_tree with
| `Contents _ -> Printf.printf "FILE \n"
| `Node _ -> Printf.printf "DIR \n" )
let () = Lwt_main.run (main ())
File "test/dune", line 2, characters 14-19:
2 | (names parse store)
^^^^^
Fatal error: exception Invalid_argument("Sync.pull_exn: Handshake got an error")
Raised at Lwt.Miscellaneous.poll in file "src/core/lwt.ml", line 3123, characters 20-29
Called from Lwt_main.run.run_loop in file "src/unix/lwt_main.ml", line 27, characters 10-20
Called from Lwt_main.run in file "src/unix/lwt_main.ml", line 106, characters 8-13
Re-raised at Lwt_main.run in file "src/unix/lwt_main.ml", line 112, characters 4-13
Called from Dune__exe__Store in file "test/store.ml", line 41, characters 9-31
Now, the error actually gets raised by ocaml-git, so perhaps I should rather report it in that repo. Nontheless, the code is virtually the same as the one found in the sync example.
Some notes:
- I am developing on nixos/WSL
- Using the URL "git://github.com/mirage/ocaml-git.git" as found in the example actually results in
Invalid_argument("Sync.pull_exn: not found") - Changing it to "https://github.com/mirage/ocaml-git" gives
Handshake got an error, so I don't think it has something to do with the particulars of the sourcehut git server. - This patch used to work: https://lists.sr.ht/~jonsterling/forester-devel/patches/51336, but I tested it on a native linux machine.
I'll try to run my code on my native linux machine. If this ends up working, I can confirm that there is a bug when running ocaml-git on WSL.
Hello! I don't have access to a windows machine to test, but your example code works out of the box on my linux... Can you confirm if the following also fails without the irmin dependency?
(executable (name test) (libraries lwt git-unix git.nss.git))
open Lwt.Syntax
open Lwt.Infix
module Store = Git_unix.Store
module Sync = Git_unix.Sync (Store)
module Uri = Smart_git.Endpoint
let src =
Uri.of_string "https://git.sr.ht/~jonsterling/public-trees" |> Result.get_ok
let main () =
let* ctx = Git_unix.ctx (Happy_eyeballs_lwt.create ()) in
let* store = Store.v Fpath.(v "/tmp" / "gitsync") >|= Result.get_ok in
let+ result = Sync.fetch ~ctx src store `All in
match result with
| Ok (Some (_hash, lst)) ->
Format.printf "Ok! Some list %#i@." (List.length lst)
| Ok None -> Format.printf "Ok! None?@."
| Error (#Mimic.error as e) ->
Format.printf "Mimic error: %a@." Mimic.pp_error e
| Error (`Exn e) -> Format.printf "Git error: %s@." (Printexc.to_string e)
| Error _ -> Format.printf "Git error: <unknown private error tag>@."
let () = Lwt_main.run (main ())
(It prints Ok! Some list 5 on my computer)
It fails! Mimic error: Handshake got an error. Should this be reported at the mimic repo, or ocaml-git?
ocaml-git seems to be the one producing the error as they are reusing the `Msg polymorphic variant to signal handshake errors, but mimic looks otherwise unrelated to the issue (it just had a nice pp_error for this test ^^)
Hi! In case it helps, I can also reproduce the Mimic error thing mentioned by @kentookura on macOS 14.5.