mirage / ocaml-git

Pure OCaml Git format and protocol
ISC License
363 stars 70 forks source link

Fatal error: exception (Failure "Unexpected end of input") #514

Closed talex5 closed 3 years ago

talex5 commented 3 years ago

I got this error from ocaml-ci-local for the first time a few days ago (on 2021-05-04):

Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
Called from Carton__Dec.weight_of_ref_delta in file "src/carton/dec.ml", line 845, characters 4-100
Called from Carton_git.Make.with_resources.(fun) in file "src/carton-git/carton_git.ml", line 150, characters 10-72
Called from Lwt.Sequential_composition.catch in file "src/core/lwt.ml", line 2023, characters 16-20
solver bug: (Failure "Unexpected end of input")
Fatal error: exception (Failure "Unexpected end of input")

I assumed there was some local corruption in my repository (and it seems to be working again for me now). But @emillon just reported the same problem. What can cause it?

emillon commented 3 years ago

Here's the contents of my switchm FYI (also happens with ocaml-git 3.2.0)

0install-solver         2.17        Package dependency solver
alcotest                1.4.0       Alcotest is a lightweight and colourful test framework
alcotest-lwt            1.4.0       Lwt-based helpers for Alcotest
angstrom                0.15.0      Parser combinators built for speed and memory-efficiency
asetmap                 0.8.1       Alternative, compatible, OCaml standard library Sets and Maps
asn1-combinators        0.2.5       Embed typed ASN.1 grammars in OCaml
astring                 0.8.5       Alternative String module for OCaml
awa                     0.0.3       SSH implementation in OCaml
awa-mirage              0.0.3       SSH implementation in OCaml
base                    v0.14.1     Full standard library replacement for OCaml
base-bigarray           base
base-bytes              base        Bytes library distributed with the OCaml compiler
base-threads            base
base-unix               base
base64                  3.5.0       Base64 encoding for OCaml
bigarray-compat         1.0.0       Compatibility library to use Stdlib.Bigarray when possible
bigstringaf             0.7.0       Bigstring intrinsics and fast blits based on memcpy/memmove
biniou                  1.2.1       Binary data format designed for speed, safety, ease of use and backwar
bos                     0.2.0       Basic OS interaction for OCaml
ca-certs                0.2.1       Detect root CA certificates from the operating system
ca-certs-nss            3.64.0.1    X.509 trust anchors extracted from Mozilla's NSS
capnp                   3.4.0       OCaml code generation plugin for the Cap'n Proto serialization framewo
capnp-rpc               1.1         Cap'n Proto is a capability-based RPC system with bindings for many la
capnp-rpc-lwt           1.1         Cap'n Proto is a capability-based RPC system with bindings for many la
capnp-rpc-net           1.1         Cap'n Proto is a capability-based RPC system with bindings for many la
capnp-rpc-unix          1.1         Cap'n Proto is a capability-based RPC system with bindings for many la
carton                  0.4.1       Implementation of PACKv2 file in OCaml
carton-git              0.4.1       Implementation of PACK file in OCaml
carton-lwt              0.4.1       Implementation of PACK file in OCaml
cf                      0.4         OCaml bindings to macOS CoreFoundation
cf-lwt                  0.4         Lwt interface to macOS CoreFoundation
checkseum               0.3.1       Adler-32, CRC32 and CRC32-C implementation in C and OCaml
cmdliner                1.0.4       Declarative definition of command line interfaces for OCaml
cohttp                  4.0.0       An OCaml library for HTTP clients and servers
cohttp-lwt              4.0.0       CoHTTP implementation using the Lwt concurrency library
cohttp-lwt-unix         4.0.0       CoHTTP implementation for Unix and Windows using Lwt
conduit                 4.0.0       A network connection establishment library
conduit-lwt             4.0.0       A portable network connection establishment library using Lwt
conduit-lwt-unix        4.0.0       A network connection establishment library for Lwt_unix
conf-capnproto          1           Virtual package relying on captnproto installation
conf-gmp                3           Virtual package relying on a GMP lib system installation
conf-gmp-powm-sec       3           Virtual package relying on a GMP lib with constant-time modular expone
conf-libev              4-11        High-performance event loop/event model with lots of features
conf-libffi             2.0.0       Virtual package relying on libffi system installation
conf-pkg-config         2           Check if pkg-config is installed and create an opam switch local pkgco
conf-sqlite3            1           Virtual package relying on an SQLite3 system installation
cppo                    1.6.7       Code preprocessor like cpp for OCaml
cpuid                   0.1.2       Detect CPU features
csexp                   1.5.1       Parsing and printing of S-expressions in Canonical form
cstruct                 6.0.0       Access C-like structures directly from OCaml
cstruct-lwt             6.0.0       Access C-like structures directly from OCaml
cstruct-sexp            6.0.0       S-expression serialisers for C-like structures
cstruct-unix            6.0.0       Access C-like structures directly from OCaml
ctypes                  0.18.0      Combinators for binding to C libraries without writing any C
ctypes-foreign          0.18.0      Virtual package for enabling the ctypes.foreign subpackage.
current_rpc             0.4         Cap'n Proto RPC plugin for OCurrent
decompress              1.4.0       Implementation of Zlib and GZip in OCaml
digestif                1.0.0       Hashes implementations (SHA*, RIPEMD160, BLAKE2* and MD5)
domain-name             0.3.0       RFC 1035 Internet domain names
duff                    0.4         Rabin's fingerprint and diff algorithm in OCaml
dune                    2.8.5       Fast, portable, and opinionated build system
dune-configurator       2.8.5       Helper library for gathering system configuration
duration                0.1.3       Conversions to various time units
easy-format             1.3.2       High-level and functional interface to the Format module of the OCaml 
emile                   1.1         Parser of email address according RFC822
encore                  0.8         Library to generate encoder/decoder which ensure isomorphism
eqaf                    0.7         Constant-time equal function on string
ethernet                2.2.0       OCaml Ethernet (IEEE 802.3) layer, used in MirageOS
extunix                 0.3.1       Collection of thin bindings to various low-level system API
fiat-p256               0.2.3       Primitives for Elliptic Curve Cryptography taken from Fiat
fmt                     0.8.9       OCaml Format pretty-printer combinators
fpath                   0.7.3       File system paths for OCaml
fsevents                0.3.0       OCaml bindings to macOS FSEvents
fsevents-lwt            0.3.0       Lwt interface to macOS FSEvents
git                     3.4.0       Git format and protocol in pure OCaml
git-cohttp              3.4.0       A package to use HTTP-based ocaml-git with Unix backend
git-cohttp-unix         3.4.0       A package to use HTTP-based ocaml-git with Unix backend
git-unix                3.4.0       Virtual package to install and configure ocaml-git's Unix backend
gmap                    0.3.0       Heterogenous maps over a GADT
hacl_x25519             0.2.2       Primitives for Elliptic Curve Cryptography taken from Project Everest
hex                     1.4.0       Library providing hexadecimal converters
hkdf                    1.0.4       HMAC-based Extract-and-Expand Key Derivation Function (RFC 5869)
hxd                     0.3.1       Hexdump in OCaml
inotify                 2.3         Inotify bindings for ocaml.
integers                0.4.0       Various signed and unsigned integer types for OCaml
ipaddr                  5.0.1       A library for manipulation of IP (and MAC) address representations
ipaddr-sexp             5.0.1       A library for manipulation of IP address representations usnig sexp
irmin-watcher           0.5.0       Portable Irmin watch backends using FSevents or Inotify
jsonm                   1.0.1       Non-blocking streaming JSON codec for OCaml
ke                      0.4         Queue implementation
logs                    0.7.0       Logging infrastructure for OCaml
lru                     0.3.0       Scalable LRU caches
lwt                     5.4.0       Promises and event-driven I/O
lwt-dllist              1.0.0       Mutable doubly-linked list with Lwt iterators
macaddr                 5.0.1       A library for manipulation of MAC address representations
macaddr-cstruct         5.0.1       A library for manipulation of MAC address representations using Cstruc
magic-mime              1.1.3       Map filenames to common MIME types
mimic                   0.0.3       A simple protocol dispatcher
mirage-clock            3.1.0       Libraries and module types for portable clocks
mirage-clock-unix       3.1.0       Unix-based implementation for the MirageOS Clock interface
mirage-crypto           0.10.1      Simple symmetric cryptography for the modern age
mirage-crypto-ec        0.10.1      Elliptic Curve Cryptography with primitives taken from Fiat
mirage-crypto-pk        0.10.1      Simple public-key cryptography for the modern age
mirage-crypto-rng       0.10.1      A cryptographically secure PRNG
mirage-device           2.0.0       Abstract devices for MirageOS
mirage-flow             2.0.1       Flow implementations and combinators for MirageOS
mirage-kv               3.0.1       MirageOS signatures for key/value devices
mirage-net              3.0.1       Network signatures for MirageOS
mirage-no-solo5         1           Virtual package conflicting with mirage-solo5
mirage-no-xen           1           Virtual package conflicting with mirage-xen
mirage-profile          0.9.1       Collect runtime profiling information in CTF format
mirage-protocols        5.0.0       MirageOS signatures for network protocols
mirage-random           2.0.0       Random-related devices for MirageOS
mirage-stack            2.2.0       MirageOS signatures for network stacks
mirage-time             2.0.1       Time operations for MirageOS
mmap                    1.1.0       File mapping functionality
mtime                   1.2.0       Monotonic wall-clock time for OCaml
nocrypto                0.5.4-2     Simpler crypto
num                     1.4         The legacy Num library for arbitrary-precision integer and rational ar
ocaml                   4.12.0      The OCaml compiler (virtual package)
ocaml-base-compiler     4.12.0      Official release 4.12.0
ocaml-ci-api            ~dev        pinned to version ~dev at git+file:///home/etienne/src/ocaml-ci#master
ocaml-compiler-libs     v0.12.3     OCaml compiler libraries repackaged
ocaml-config            2           OCaml Switch Configuration
ocaml-migrate-parsetree 2.1.0       Convert OCaml parsetrees between different versions
ocaml-options-vanilla   1           Ensure that OCaml is compiled with no special options enabled
ocaml-syntax-shims      1.0.0       Backport new syntax to older OCaml versions
ocamlbuild              0.14.0      OCamlbuild is a build system with builtin rules to easily build most O
ocamlfind               1.9.1       A library manager for OCaml
ocamlgraph              2.0.0       A generic graph library for OCaml
ocb-stubblr             0.1.1-1     OCamlbuild plugin for C stubs
ocplib-endian           1.1         Optimised functions to read and write int16/32/64 from strings and big
opam-0install           0.4.1       Opam solver using 0install backend
opam-core               2.1.0~beta4 opam 2.1 development libraries (core)
opam-file-format        2.1.2       Parser and printer for the opam file syntax
opam-format             2.1.0~beta4 opam 2.1 development libraries (format)
opam-repository         2.1.0~beta4 opam 2.1 development libraries (repository)
opam-state              2.1.0~beta4 opam 2.1 development libraries (state)
optint                  0.1.0       Efficient integer types on 64-bit architectures
parsexp                 v0.14.0     S-expression parsing library
pbkdf                   1.1.0       Password based key derivation functions (PBKDF) from PKCS#5
pecu                    0.5         Encoder/Decoder of Quoted-Printable (RFC2045 & RFC2047)
ppx_cstruct             6.0.0       Access C-like structures directly from OCaml
ppx_derivers            1.2.1       Shared [@@deriving] plugin registry
ppx_deriving            5.2.1       Type-driven code generation for OCaml
ppx_deriving_yojson     3.6.1       JSON codec generator for OCaml
ppx_sexp_conv           v0.14.3     [@@deriving] plugin to generate S-expression conversion functions
ppxlib                  0.22.0      Standard library for ppx rewriters
prometheus              1.0         Client library for Prometheus monitoring
prometheus-app          1.0         Client library for Prometheus monitoring
psq                     0.2.0       Functional Priority Search Queues
ptime                   0.8.5       POSIX time for OCaml
randomconv              0.1.3       Convert from random byte vectors (Cstruct.t) to random native numbers
re                      1.9.0       RE is a regular expression library for OCaml
res                     5.0.1       RES - Library for resizable, contiguous datastructures
result                  1.5         Compatibility Result module
routes                  0.8.0       Typed routing for OCaml applications
rresult                 0.6.0       Result value combinators for OCaml
seq                     base        Compatibility package for OCaml's standard iterator type starting from
session                 0.4.1       A session manager for your everyday needs
session-cohttp          0.4.1       A session manager for your everyday needs - Cohttp-specific support
session-cohttp-lwt      0.4.1       A session manager for your everyday needs - Cohttp-specific support fo
sexplib                 v0.14.0     Library for serializing OCaml values to and from S-expressions
sexplib0                v0.14.0     Library containing the definition of S-expressions and some base conve
sqlite3                 5.0.3       SQLite3 bindings for OCaml
stdint                  0.7.0       Signed and unsigned integer types having specified widths
stdio                   v0.14.0     Standard IO library for OCaml
stdlib-shims            0.3.0       Backport some of the new stdlib features to older compiler
stringext               1.6.0       Extra string functions for OCaml
tcpip                   6.1.0       OCaml TCP/IP networking stack, used in MirageOS
tls                     0.13.1      Transport Layer Security purely in OCaml
tls-mirage              0.13.1      Transport Layer Security purely in OCaml, MirageOS layer
topkg                   1.0.3       The transitory OCaml software packager
tyxml                   4.5.0       A library for building correct HTML and SVG documents
uchar                   0.0.2       Compatibility library for OCaml's Uchar module
uri                     4.2.0       An RFC3986 URI/URL parsing library
uri-sexp                4.2.0       An RFC3986 URI/URL parsing library
uuidm                   0.9.7       Universally unique identifiers (UUIDs) for OCaml
uutf                    1.0.2       Non-blocking streaming Unicode codec for OCaml
x509                    0.13.0      Public Key Infrastructure (RFC 5280, PKCS) purely in OCaml
yojson                  1.7.0       Yojson is an optimized parsing and printing library for the JSON forma
zarith                  1.12        Implements arithmetic and logical operations over arbitrary-precision
emillon commented 3 years ago

In the context of ocaml-ci, the issue happens at ocurrent/ocaml-ci@682d873da3af983372fb4a4a1ebea74bc9fc5be3 when I upgrade git-unix from 2.1.3 to 3.2.0.

dinosaure commented 3 years ago

The stack trace does not really help but it seems related to decompress which has a recent fix about eof/eob but not released yet (I need to tests some others things). Can you upgrade decompress with its current state & retry please?

Then, to be able to reproduce, I think it's when you want to clone a repository. If it's the case, the best is to tell me which repository you want to clone and I can try to reproduce the error.

talex5 commented 3 years ago

I think it's when trying to read from opam-repository. But note that it is cloned using the C git tool; ocaml-git is only used for reading it after the clone is already done.

emillon commented 3 years ago

I tried pinning decompress to the current master and it fails too. In case that helps, I'm using git (the C one) 2.30.2.

dinosaure commented 3 years ago

Ok, the problem still is decompress 👍 but we can identify more precisely what is wrong. So in that case, a PACK file (or loose file - but I suspect more a PACK file) has a zlib object which decompress can not inflate. May be you should try to run ocaml-ci with the debug level on logs. Then, the failwith should appear just after a try to read a specific object.

This object then should exists into the PACK and the best, for me, will be to know which object decompress fails and where we can find this object. Two possibilities exists then:

PS: when you get the hash of the Git object (from logs), you are able to find it into .git/objects/. If it's a loose object, for instance 7564d3e..., it should be located into .git/objects/75/64d3e.... If the object is into the PACK file, you can list them into .git/objects/pack. Then, a git verify-pack -v on them lists all Git objects inside, so you just need to find one PACK file which contains the hash of the Git object.

emillon commented 3 years ago

All right! I set the debug level to Debug and the log ends with:

2021-05-07 17:19.03     carton-git [DEBUG] Start to load the object from the PACK file.
2021-05-07 17:19.03     carton-git [DEBUG] Object 0eb9df935b2e0f67411ab7c28c53e40dfbb5b17a loaded.
2021-05-07 17:19.03      git.store [DEBUG] 0eb9df935b2e0f67411ab7c28c53e40dfbb5b17a found.
2021-05-07 17:19.03     git.search [predecessor] Read the object: 27c189ceb3461d230c661ea595a864abf4d8bce8.
2021-05-07 17:19.03      git.store [DEBUG] Git.read 27c189ceb3461d230c661ea595a864abf4d8bce8
2021-05-07 17:19.03     carton-git [DEBUG] 27c189ceb3461d230c661ea595a864abf4d8bce8 exists into the *.idx file? false
...line above repeated many times...
2021-05-07 17:19.03     carton-git [DEBUG] Start to load the object from the PACK file.
2021-05-07 17:19.03     carton-git [DEBUG] Object 27c189ceb3461d230c661ea595a864abf4d8bce8 loaded.
2021-05-07 17:19.03      git.store [DEBUG] 27c189ceb3461d230c661ea595a864abf4d8bce8 found.
2021-05-07 17:19.03      git.store [DEBUG] Git.read 2e35b059eee64fcf778276e324c9de23f4ecc82b
2021-05-07 17:19.03     carton-git [DEBUG] 2e35b059eee64fcf778276e324c9de23f4ecc82b exists into the *.idx file? false
...line above repeated many times...
2021-05-07 17:19.03     carton-git [DEBUG] Start to load the object from the PACK file.
Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
Called from Carton__Dec.weight_of_ref_delta in file "src/carton/dec.ml", line 845, characters 4-100
Called from Carton_git.Make.with_resources.(fun) in file "src/carton-git/carton_git.ml", line 150, characters 10-72
Called from Lwt.Sequential_composition.catch in file "src/core/lwt.ml", line 2023, characters 16-20
solver bug: (Failure "Unexpected end of input")
Fatal error: exception (Failure "Unexpected end of input")
Raised at Dune__exe__Solver.main in file "solver/solver.ml", line 90, characters 4-12
Called from Dune__exe__Main in file "solver/main.ml", line 54, characters 37-82
dinosaure commented 3 years ago

So the object is 2e35b059eee64fcf778276e324c9de23f4ecc82b. Now it's depending on the layout of the PACK file. I believe that you have many PACK files and one of them has the object 2e35b059eee64fcf778276e324c9de23f4ecc82b. In that case, the best for me (to try to debug) is to give the PACK file which contains the object.

Again, git verify-pack -v (into .git/objects/pack) can help you to find the right PACK file. So if you have an access to the disk, it will help me a lot to give the PACK file.

emillon commented 3 years ago

I found the repo, and that object seems to be in several pack files:

for p in ./opam-repository/objects/pack/*.pack ; do
    git verify-pack -v $p | grep 2e35b059eee64fcf778276e324c9de23f4ecc82b && echo $p
done
2e35b059eee64fcf778276e324c9de23f4ecc82b blob   51 64 8035035 2 22fb8f4f4bf5d28712deae99ad1da40fdca2d813
./opam-repository/objects/pack/pack-0d82edf19c1875d3a83b211402625b0b730b7004.pack
2e35b059eee64fcf778276e324c9de23f4ecc82b blob   51 64 8070565 2 22fb8f4f4bf5d28712deae99ad1da40fdca2d813
./opam-repository/objects/pack/pack-2f7e0619ced970233d6b22bade931aed69db9d1f.pack
2e35b059eee64fcf778276e324c9de23f4ecc82b blob   51 64 8032473 2 22fb8f4f4bf5d28712deae99ad1da40fdca2d813
./opam-repository/objects/pack/pack-6aff34deb0a28cd949c3a187579b741d25e8eb7f.pack
2e35b059eee64fcf778276e324c9de23f4ecc82b blob   51 64 7463577 2 22fb8f4f4bf5d28712deae99ad1da40fdca2d813
./opam-repository/objects/pack/pack-fada1074671b7f8d75e2a7aa317f4b73a77e2f57.pack

I'll send you the files privately.

dinosaure commented 3 years ago

Can you try with #515? The error is about decompress but it exists only with carton which gives an empty payload to decompress (and logically said that it waiting something).

emillon commented 3 years ago

Yes, the fix works. Thanks!

dinosaure commented 3 years ago

Will do a minor release of carton which will include the fix. Thanks for the report.