Sunday, November 29, 2026

Boring vs Interesting Code

Interesting and advanced code is hard to come by, especially in the world of small business.  (We just don’t have the volume to “need” to solve the C10K Problem, let alone needing Linux kernel hackers.)  The bulk of requests to the teams I have worked on have been for reporting, ETL jobs, and random tasks like “client Alexandria needs to move from tenant 3 to tenant 7, but Tina [the agent in tenant 3 who is assigned as the client’s owner] still needs to have access.”

A certain amount of sysadmin work is fundamentally boring, too.  I wrote a system to build AMIs with our apps preloaded, but the algorithm and structure aren’t really important.  It’s straight-line procedural code that does what needs to be done, reading configuration, installing packages, placing files, marking things as finished so it doesn’t try to repeat them, and so forth.

The call to work magic is much rarer.  Only two examples come immediately to mind.

For one, I built a training video system using an off-the-shelf player and CloudFront’s RTMP distribution support.  I was also able to build usage metrics for this system, something we didn’t have with our previous provider, which ended up revealing a 1% usage rate.  That justified shutting down the whole system, thankfully before CloudFront removed RTMP.

When a client wanted to limit contracts based on arbitrary properties of the assets, I built a language so that we could express those conditions through storing expressions in the database.  I would later port this to PHP.  There was no parser generator, so I hand-built a parser instead.  Tests were ported to ensure parity between the two parsers.

In hindsight, something becomes clear.

If the vast majority of business code is low-hanging fruit, and an LLM can pick it, then a business can reasonably see immense potential in LLMs for everyday operations.  This promise can easily overshadow the risks of becoming unable to handle an extraordinary problem that needs much higher capability to resolve.

Sunday, October 18, 2026

Notes on my Dovecot 2.3 to 2.4 Upgrade

I last wrote about my mail system two years ago, in which I coaxed Dovecot 2.3 into accepting my authentication philosophy.  In those days, user@domain would be looked up through /local/auth/domain/passwd containing only user as its first column.  I ended up abandoning this approach for Dovecot 2.4.

An aside: it was initially very helpful in this conversion process to use doveconf -n to get configuration error messages, instead of asking systemd to start the service and then having to look at the (truncated by default) journal for the error message.

I have decided to store the full user@domain in the file now, even if the domain part is redundant, because it makes life a lot easier.  There’s no need to modify the user on a lookup result this way.  This simplifies the configuration in 2.4:

passdb auth_passwd_file {
    passwd_file_path = /local/auth/%{user | domain | lower}/passwd
    driver = passwd-file
}
userdb auth_passwd_file {
    passwd_file_path = /local/auth/%{user | domain | lower}/passwd
    driver = passwd-file
}

Most other problems were caused by Debian’s updated defaults conflicting with my environment.

Their 10-auth.conf file sets “system users through PAM” as the first option for authentication, before my local.conf was included, so I would get a “pam_unix: unknown user” message on every login attempt.  Worse, this would permit someone to authenticate as system users that should not have email service.  I ended up commenting out the include line for auth-system.conf.ext directly.

The other major problem was that they set mail_inbox_path in their 10-mail.conf file.  Instead, I want my local configuration to take effect:

mail_driver = maildir
mail_path = ~/.maildir

I don’t set mail_inbox_path, and mail_home ends up coming from the passwd file itself.  Previously, that file had /home/user/.maildir as a home directory, and these settings created /home/user/.maildir/.maildir as an empty folder structure.  I decided to take the trailing /.maildir out of my passwd file, rather than unsetting the path.  This keeps non-mailbox stuff, like sieve scripts, out of the mailbox.

Sunday, October 11, 2026

Apache/PHP-FPM: all fun and games until someone uses Proxy

Recently at work, files started being owned by the wrong user.  Ultimately, I would find that the culprit was a buffering change unexpectedly interacting with SetHandler directives in Apache.

Some experimentation had demonstrated that PHP’s flushing functions were not working to generate output immediately, and the slop machine suggested adding a simple little config block:

<Proxy "fcgi://localhost">
    ProxySet flushpackets=on
</Proxy>

Once this is present, all SetHandler "...|fcgi://localhost" directives become “shared workers”, and Apache assumes that all the sockets defined in the SetHandler are alternate paths to the same destination. Requests can suddenly be routed to the wrong worker pool.  To fix it, our secondary SetHandler needed to carry a different ID than “localhost”, as in:

SetHandler "unix:proxy:/run/php/sns.sock|fcgi://deploy"

With different IDs, the destinations are treated as distinct once again.

Sunday, August 30, 2026

Using zerofree to reduce Ubuntu 26.04 (resolute) / Debian 14 (forky) OVA size

This is an update of an older post, because the instructions there stopped working.

Ubuntu 26.04 is the first LTS after Canonical switched from initramfs-tools to dracut in 25.10.  The break=init parameter doesn’t work anymore on 26.04; the system simply performs a normal boot in that case.  I believe that Debian plans to do the same in their next release, 14 (forky).

Dracut builds an initrd that responds to a different parameter, with a different set of break points.  Full information about rd.break is located in the dracut.cmdline man page, but for our purposes, we’ll use rd.break=pre-mount to get a shell before the root filesystem is mounted.  If we build zerofree into the initrd temporarily, then everything we need will be available in that environment.

In full, this process looks like this:

  1. From the prepared system, run: sudo dracut --force --install zerofree
  2. Reboot in graphical mode, or shut down and do a graphical-mode restart, as applicable.
  3. Interrupt the boot loader to add rd.break=pre-mount to the kernel command line.  (This general process is more fully described in the older post.)
  4. Boot.
  5. Press Enter (or enter root password, as required) to get to the initramfs shell.
  6. Run zerofree -v [DEVICE] at the initramfs prompt (replace [DEVICE] with the actual device; this operation shouldn’t damage anything, but for reliability, double or triple-check the device name!)
  7. Run poweroff when it’s done.

The machine is now prepared for export.

Sunday, July 26, 2026

Using IPv4 for Outbound SMTP in Postfix

I got a rejection notice from Microsoft Office 365.  My email couldn’t be delivered, they said, because it was on the Spamhaus malware-source list.  Sure enough, the /64 was on it… which, I guess, might be the prefix for the entire data center? at my VPS provider.  All I get is a measly /128.

Point being, I wanted to send outbound mail over IPv4 only, while keeping inbound mail available on IPv6.  Thanks to slop, the internet didn’t know how to do it conditionally.  I ended up modifying my /etc/postfix/master.cf to include the configuration on the smtp client only:

smtp    unix    -   -   y   -   -   smtp
    -o inet_protocols=ipv4

The change here is adding the inet_protocols configuration line under the “smtp” UNIX service (first on line), handled by the “smtp” client (last on line).

I worked this out from scattered hints in various documentation, but in a broader search, I managed to find Postfix’s own corroboration of what I did.

I can no longer deliver to IPv6-only MX hosts, but in the short run, that’s far less of a concern than being unable to deliver to dualstack hosts which reject my IPv6 but not my IPv4.  The long-term solution is some sort of smtp_protocol_map that I could specify IPv4-only “for Microsoft” and let the rest of the Internet use IPv6 if it wanted to, but I don’t think Postfix supports that.

The information about my specific server applies to Postfix 3.8 shipped with Ubuntu 24.04 LTS.

Sunday, June 21, 2026

Defaults Aren’t Always Good

I am responsible for a b2b system with a few dozen per-client settings, many of which are old and have defaults.  For instance, there is the grace period, which allows a limited self-service time window for clients to enter data that was missed during the normal course of business.  It seemed like a good idea at the time, but now we have a set of invisible values hidden in code holding those defaults.  And we can’t change them.

The main problem is, changing a default is an operational change to an unknown scope of clients.  On top of that, there could be clients that have the current default explicitly configured: would we want to change them, too?  It probably loops in the CEO and takes at least a week of meetings to answer that.

From a b2b business standpoint, it is actually better to require a configuration value (and let the support team view/modify it), even if it introduces the possibility of failure.  Our clients will use the normal support channel (well-oiled and always staffed) to raise the error message to us, if tech doesn’t proactively alert themselves about it.

For an ecommerce or public website where users would just leave, it’s probably more costly to “crash on error” than it is to let an errant process continue.  But if management prefers to halt and catch fire, the defaults are the opposite of that.

Sunday, June 14, 2026

The Lock Wait Timeouts: MySQL’s SELECT … FOR UPDATE OF t1

We had an issue with our busiest client, where some updates were failing with a “lock wait timeout."  These were updates of a single row in a single table, and when I ran out of my own ideas, I threw it at an LLM.

The research phase

The main weakness of LLMs is that they’re unliely to say, “I don’t know.  Maybe it’s not here."  Hence, the first thing I did was play along and waste a week on “lock ordering” changes, so that tables would be locked in a consistent order across the main site.  We (someone else with an LLM) identified one query doing a full table scan up front, which would lock everything unintentionally.  But with that fixed, and other ordering changes in place, there was a 0.0% reduction in problems in production.

With my human insight, I looked outside the subsystem, and used the LLM again to analyze the access logs; this found a long-running request in the administrative backend, which was active at the time of the lock-wait errors.  I rediscovered internal timing logs from the admin area, and they confirmed the activity with a narrower time window, but I still didn’t know what was wrong yet.

The final clue came when I had an LLM generate code to instrument the main site, to show lock status when receiving a timeout error.  When the resulting spam was run back through the LLM, it pointed to the contract type table as the source of the failures.  But, the admin page wasn’t planning to write to the type, only the contract itself.  The problem was clearly that it had acquired too strong of a lock.

The actual problem

SELECT … FOR UPDATE in MySQL/InnoDB acquires a write lock on all records scanned. This means means that selecting from t1 and joining two other tables will take write locks on all three tables. For us, blocking reads of contract types would behave the same as locking all contracts of that type, across a much larger number of queries for unrelated contracts.

To limit which tables have write locks acquired, MySQL extended the syntax: SELECT … FOR UPDATE OF t1 will lock only t1 for writing.  Multiple tables can still be locked by comma-separating them.  There’s an additional option which may follow, the NOWAIT (fail the statement if any matched rows are already locked) or SKIP LOCKED (do not lock or return rows which are already locked by another thread.)  Without options, the normal “wait for locks” behavior applies.  Hence, the final statement shape may look something like:

SELECT … FOR UPDATE OF t1, t2 SKIP LOCKED;
SELECT … FOR UPDATE OF t1 NOWAIT;
SELECT … FOR UPDATE OF t1;

We haven’t seen another lock wait timeout since putting this small change into production, which is anywhere from a 0 to 100% decrease in failures.  We will never know exactly, because I couldn’t leave well enough alone.  Next week, we’ll release another change that segments the work in the admin page.  Instead of locking “up to the limit” rows at once, it will lock in blocks of 20, and stream the results.