Thomas Leonard's work notes

(see roscidus.com for my main blog)

(Uring sockaddrs and cohttp framing)

Eio

GongYuanCaiJi reported a problem on eio_linux where an Executor_pool can't create the requested number of domains because it hits the OS limit on locked memory. The main cause of this is that each domain allocates an io_uring fixed buffer, which uses a fair bit of locked memory.

I'd been meaning to disable fixed buffers by default anyway (they're not much help in my experience, and they trigger a nasty bug in older kernels when using ZFS). Disabling them by default required providing a way to turn them back on if you do want them, and I wanted a generic system that didn't force you to depend on eio_linux (so that you can say you want a fixed buffer if eio_linux is used, but without preventing compilation on other platforms):

  • Add Eio_unix.Backend_config and disable fixed buffers by default #960.

Uring

Thomas Gazagnaire reported that using Eio.Net.send ~dst failed with EINVAL for Unix-domain sockets on eio_linux. Tracing things with bpftrace, I found that Linux's unix_dgram_sendmsg was rejecting the address dst for being longer than the maximum size of a Unix-domain address!

This was due to a confusion in ocaml-uring about the length field: when receiving an address we need to give the total size of the buffer, but when sending we need the exact length of the actual address. We hadn't noticed this before because it doesn't matter for IP addresses (which have a known and fixed size).

Fixing the sending side was easy enough, but I had to change the Uring.Msghdr API slightly to fix a related bug on the receiving side:

  • Fix Msghdr API for receiving an address #163.
  • Fix send_msg ~dst #165.

While testing that, I noticed that CI sometimes failed if it used one of the really old riscv machines for the test, so I extended the use of mdx_skip in the tests to deal with that:

  • Fix test on older Linux versions #164.

I'm now in the process of releasing the fixed uring and updating Eio to use it:

  • Prepare release #166.
  • [new release] uring (2.15.1) #31118.
  • Update to new uring API #966.

Cohttp

Ville Vesilehto has been looking for bugs in cohttp-eio and I reviewed some proposed fixes.

If your request handler gets a body but doesn't read it, then cohttp-eio would interpret the body as the next request:

  • cohttp-eio: drain unread request bodies #1151.

Also, cohttp assumes that some methods (like GET) can't have bodies, which means it doesn't know to skip them if they do:

  • http: frame request bodies independently of method #1152.

It would be good to have a core cohttp maintainer look at these; I suspect they might affect other backends too.