ocaml-batteries-team/batteries-included — Issue #178: Possible bug in BatEnum.lines_of
Author: pdonadeo
Created: 2011-11-06 13:44:47+00:00
State: open

I'm writing a simple client reading text lines (a 'mail.log' generated by Postfix) from a Unix socket, and I'm using BatEnum.lines_of to iterate over the lines. After a few iterations this exception is raised:

> Fatal error: exception Sys_error("Bad file descriptor")
> Raised by primitive operation at unknown location
> Called from file "src/batInnerIO.ml", line 378, characters 25-38
> Called from file "src/batInnerIO.ml", line 484, characters 10-21
> Called from file "src/batInnerIO.ml", line 501, characters 2-8
> Re-raised at file "src/batInnerIO.ml", line 471, characters 2-94
> Called from file "src/batIO.ml", line 149, characters 6-9
> Re-raised at file "src/batIO.ml", line 151, characters 35-65
> Called from file "src/batEnum.ml", line 543, characters 13-22
> Re-raised at file "src/batEnum.ml", line 545, characters 23-32
> Called from file "src/batEnum.ml", line 363, characters 16-26
> Called from file "src/batEnum.ml", line 367, characters 2-8
> Re-raised at file "src/batEnum.ml", line 346, characters 2-98
> Called from file "broken_client.ml", line 6, characters 0-94

What is strange is that lines_of doesn't use magic of any type and if I actually redefines my own lines_of, everything works as it should.

To reproduce the bug you need a simple server written in Python, available [here](https://gist.github.com/1342885#file_server.py), and the broken client, [here](https://gist.github.com/1342885#file_broken_client.ml). You also need a text file, named mail.log in the source example.

Start the server and, in another console, start the client.

A naive working re implementation of lines_of is [here](https://gist.github.com/1342885#file_working_client.ml).

OCaml 3.12.1
Batteries 1.4.0

Is it only me or you can reproduce the bug?