bash – Tab Completion Hangs in Bash

autocompleteautomountingbash

When I first open a terminal, or open a new one after not having used one for a while, any kind of tab completion in my home directory (for example, ls and Tab) takes several seconds. I have seen this behavior before when using autofs to mount network drives, but I don't have any in ~/. I do mount NFS shares with systemd's automount, but those are in ~/badabing/, so everything in ~/ itself is just a local file.

In case it is an automount issue, here are the relevant /etc/fstab lines (yes, the server is called "badabing", I named it during a Sopranos binge a few years ago):

badabing:/nfs_shares/music /mnt/badabing/music    nfs4  noauto,x-systemd.automount,x-systemd.device-timeout=5sec,x-systemd.idle-timeout=1min    0 0
badabing:/nfs_shares/series /mnt/badabing/series  nfs4  noauto,x-systemd.automount,x-systemd.device-timeout=5sec,x-systemd.idle-timeout=1min    0 0
badabing:/nfs_shares/movies /mnt/badabing/movies  nfs4  noauto,x-systemd.automount,x-systemd.device-timeout=5sec,x-systemd.idle-timeout=1min    0 0

Then, in ~/badabing I have:

$ ls -l ~/badabing/
total 0
lrwxrwxrwx 1 terdon terdon 32 Jan 10  2016 movies -> /mnt/badabing/nfs_shares/movies/
lrwxrwxrwx 1 terdon terdon 31 Jan 10  2016 music -> /mnt/badabing/nfs_shares/music/
lrwxrwxrwx 1 terdon terdon 31 Jan 10  2016 series -> /mnt/badabing/nfs_shares/series

I'd like to investigate this more. Can I somehow strace tab completion? Is the only way to add echo commands in the various bash completion scripts to see what's hanging? There are quite a few of those so I'd really rather avoid that.

So, what's causing this or, at least, how can I debug it further?

Best Answer

I would do this:

sudo strace -pXXXX -tfo /tmp/strace.log

where XXXX is the process id of bash. In a quick check of filename completion on one of my NFS-mounted directory trees, it works without problems:

-f

Trace child processes as they are created by currently traced processes as a result of the fork(2) system call.

-t

Prefix each line of the trace with the time of day.

Some people might prefer -r:

-r

Print a relative timestamp upon entry to each system call. This records the time difference between the beginning of successive system calls.

Related Question