ocaml-uri
ocaml-uri copied to clipboard
Uri is not thread/domain safe
We encountered the following:
Fatal error: exception CamlinternalLazy.Undefined
Raised at CamlinternalLazy.force_gen_lazy_block in file "camlinternalLazy.ml", line 75, characters 9-24
Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml" (inlined), line 78, characters 27-67
Called from Angstrom.fix_direct.(fun) in file "lib/angstrom.ml", line 460, characters 4-18
Called from Angstrom__Parser.parse_bigstring in file "lib/parser.ml", line 43, characters 52-93
Called from Uri.Parser.uri_reference.(fun) in file "lib/uri.ml", line 1066, characters 12-63
Called from Angstrom__Parser.Monad.(>>|).(fun).succ' in file "lib/parser.ml", line 64, characters 61-66
Called from Angstrom__Parser.parse_bigstring in file "lib/parser.ml", line 43, characters 52-93
Called from Uri.of_string in file "lib/uri.ml", line 1148, characters 8-68
Our program runs multiple domains in parallel.
I spent a brief moment to look through the Uri and Angstrom code bases. I strongly suspect the problem is that the Uri.Parser module uses the Angstrom fix combinator, which uses lazy internally. The problem with that is that Lazy is not safe to use concurrently / in parallel — an attempt to do so may raise the Undefined exception. As a workaround we will try to force the parser before spawning domains, but this should really be fixed properly.