Thomas Leonard's work notes

(see roscidus.com for my main blog)

(ptys, getaddrinfo, chown)

I've been continuing to fix issues and review PRs on Eio and uring.

Eio and uring

I reviewed and merged Anil's pseudoterminal support PR (started in 2023!), which allows running a subprocess with a virtual terminal, controlled by the parent:

  • Support for creating ptys and a login_tty fork_action #531.

The main issue here was making it work in harmony with Eio's inherit_fds feature.

I reviewed and merged chown support (similar to the chmod support added last time).

  • Support chown in eio_posix and eio_linux #781.

I failed to spot some important problems with the new code, but luckily Anil noticed them soon after the merge:

  • Use the right flags for chown and add a linux/other test #864.
  • chmod: prevent sandbox escape using symlinks #872.
  • chown: prevent sandbox escape using symlinks #877.

OCaml's Unix.getaddrinfo returns [] (no results) on any error, which can be confusing as it hides the real error. For example, you can be told that a name doesn't exist when in fact the process has just reached its limit on the number of open FDs! I updated an old PR from Christiano which raises a suitable exception instead (the problem with the old PR was that it was based on OCaml's code, but the OCaml developers weren't willing to let us use it so it needed to be reimplemented):

  • Report errors from getaddrinfo #866.

Disappointingly, it turned out that the underlying getaddrinfo implementation in glibc also fails to propagate the FDs-limit error!

I updated Eio to use the safer Res.t result type we recently added to uring:

  • eio_linux: use Uring.Res module for safer error handling #868.

We had some discussion about whether the code for reading string-valued socket options was correct, and made the code a bit stricter:

  • Be more careful about unterminated string socket options #876.

Path.load didn't work correctly with files in /proc, which report a size of 0 but do have content. Worked with Patrick to get that fixed:

  • Allow Eio.Path.load to handle files with zero size #869.

It turns out that you also have to be careful about buffer sizes when reading from /proc, as Linux can give incorrect results for small buffers:

  • Use a sensible minimum buffer size for Path.load #878.

I learnt about Linux's /proc/pressure/io system, and investigated a report that Eio was causing excessive pressure (it turned out to be a known problem in Linux with uring):

  • High iowait/IO pressure reported for an idle Eio io_uring service #862.

Other minor PR reviews:

  • eio_windows: fix removing of FDs from read/write sets #861.
  • Switch fstat to statx on linux and fetch blksize #865.
  • fork_action: retry on eintr when writing to pipe #870.
  • eio_linux: these read/write functions didn't hold the fd open #871.
  • eio_posix, eio_windows: map ENOPROTOOPT to Invalid_option #874.
  • Add bindings for vectored read/writev fixed buffers #155.
  • Update to liburing.2.15 #157.
  • uring: update min to 2.15.0+ so we can use new functionality #867.

Prometheus

I also made a few minor cleanups in mirage/prometheus:

Thomas Gazagnaire noticed that it was formatting floats with %f, losing some precision:

  • Format floats with %.17g #62.

Prometheus also had some dependencies that aren't needed with modern compiler versions:

  • Remove Astring dependency #63.
  • Remove dependency on Asetmap #64.

At some point Prometheus needs some larger refactoring, to split off the Lwt parts from the core.