John Goerzen: Pipes, deadlocks, and strace annoyingly fixing them
This is a complex tale I will attempt to make simple(ish). I ve (re)learned more than I cared to about the details of pipes, signals, and certain system calls and the solution is still elusive.
For some time now, I have been using NNCP to back up my files. These backups are sent to my backup system, which effectively does this to process them (each ZFS send is piped to a shell script that winds up running this):
gpg -q -d zstdcat -T0 zfs receive -u -o readonly=on "$STORE/$DEST"This processes tens of thousands of zfs sends per week. Recently, having written Filespooler, I switched to sending the backups using Filespooler over NNCP. Now fspl (the Filespooler executable) opens the file for each stream and then connects it to what amounts to this pipeline:
bash -c 'gpg -q -d 2>/dev/null zstdcat -T0' zfs receive -u -o readonly=on "$STORE/$DEST"Actually, to be more precise, it spins up the bash part of it, reads a few bytes from it, and then connects it to the zfs receive. And this works well almost always. In something like 1/1000 of the cases, it deadlocks, and I still don t know why. But I can talk about the journey of trying to figure it out (and maybe some of you will have some ideas). Filespooler is written in Rust, and uses Rust s Command system. Effectively what happens is this:
- The fspl process has a File handle, which after forking but before invoking bash, it dup2 s to stdin.
- The connection between bash and zfs receive is a standard Unix pipe.
- bash is blocking in wait4(), which is expected.
- gpg is blocking in write().
- If I attach to zstdcat with strace -p, then all of a sudden the deadlock is cleared and everything resumes and completes normally.
- Attaching to zfs receive with strace -p causes no output at all from strace for a few seconds, then zfs just writes cannot receive incremental stream: incomplete stream and exits with error code 1.
int err = zfs_file_read(fp, (char *)buf + done,
len - done, &resid);
if (resid == len - done)
/*
* Note: ECKSUM or ZFS_ERR_STREAM_TRUNCATED indicates
* that the receive was interrupted and can
* potentially be resumed.
*/
err = SET_ERROR(ZFS_ERR_STREAM_TRUNCATED);
resid is an output parameter with the number of bytes remaining from a short read, so in this case, if the read produced zero bytes, then it sets that error. What s zfs_file_read then?
It boils down to a thin wrapper around kernel_read(). This winds up calling __kernel_read(), which calls read_iter on the pipe, which is pipe_read(). That s where I don t have the knowledge to get into the weeds right now.
So it seems likely to me that the problem has something to do with zfs receive. But, what, and why does it only not work in this one very specific situation, and only so rarely? And why does attaching strace to zstdcat make it all work again? I m indeed puzzled!
Update 2022-06-20: See the followup post which identifies this as likely a kernel bug and explains why this particular use of Filespooler made it easier to trigger.
In May I was assigned 11 hours of work by Freexian's Debian LTS
initiative and carried over 13 hours from April. I worked 8 hours,
and will carry over the remaining time to June.
I spent some time triaging security issues for Linux, working out
which of them were fixed upstream and which actually applied to the
versions provided in Debian 9 "stretch". I rebased the Linux 4.9
(linux) package on the latest stable update, but did not make an
upload this month. I started backporting several security fixes to
4.9, but those still have to be tested and reviewed.
A short while after
As announced some time ago on
My work computer runs Debian 11 bullseye (the current stable release) in a mechanical 500GB disk, and I was provided with a new SDD disk but its size was 480 GB. So I had to shrink my partitions before copying the data to the new disk. It turned out to be a bit difficult because my main partition was encrypted.
I write here how I did, maybe there are other simpler ways but I couldn t find them.
References:
(Well, the actual process was not so smooth but after several tries and errors and searching for help I managed to get the needed commands to make my system boot from the new disk).







Youtube has a really nice RSS feature that is extremely well hidden.
If you postfix a Channel ID to
Now, some user pages may have multiple valid RSS feeds because they contain multiple channels.
Remember the TED page from above? Well run:
You probably want the last Channel ID listed above, the non-selective "TED" one. And that's the one from the example above.
Update
02.06.2022:
smpl wrote in and has the much better solution for the most frequent use cases: