mirage / irmin

Irmin is a distributed database that follows the same design principles as Git
https://irmin.org
ISC License
1.83k stars 154 forks source link

exception Invalid_argument("Sync.pull_exn: Handshake got an error") when using Sync #2319

Open kentookura opened 2 months ago

kentookura commented 2 months ago

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'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.

art-w commented 2 months ago

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)

kentookura commented 2 months ago

It fails! Mimic error: Handshake got an error. Should this be reported at the mimic repo, or ocaml-git?

art-w commented 2 months ago

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 ^^)

jonsterling commented 2 months ago

Hi! In case it helps, I can also reproduce the Mimic error thing mentioned by @kentookura on macOS 14.5.