Subject: bug#72641: 31.0.50; "Unlocking file: Invalid argument" when deleting lock file on network file system

From: Michal Nazarewicz <[email-masked]>
Date: Sat, 17 Aug 2024 22:03:24 +0200

This appears to be network synchronisation issue.  I’ve run this
program:

---------- >8 --------------------------------------------------
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void create(char *path) {
	int ret = symlink("dummy", path);
	if (ret < 0) {
		printf("%s: %d %s\n", path, errno, strerror(errno));
	} else {
		printf("%s: Ok\n", path);
	}
}

int check(char *path) {
	char buf[1024];
	ssize_t ret = readlink(path, buf, 1024);
	if (ret >= 0) {
		printf("%s: %.*s\n", path, ret, buf);
		return 0;
	}
	int err = errno;
	printf("%s: %d %s\n", path, err, strerror(err));
	return err;
}

int main(int argc, char **argv) {
	char *path = argc < 2 ? "bar" : argv[1];
	create(path);
	int loop = 0;
	while (check(path) != EINVAL && ++loop < 50) {
		usleep(100000);
	}
	return 0;
}
-------------------------------------------------- 8< ----------

and got the following:

---------- >8 --------------------------------------------------
/o/foo: 5 Input/output error
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 2 No such file or directory
/o/foo: 22 Invalid argument
-------------------------------------------------- 8< ----------

It looks like symlink(2) fails with EIO while the server creates
a regular file, however it takes the client to notice another second.

If you’re still interested, here’s strace when I find-file and then
kill-current-buffer without saving:

---------- >8 --------------------------------------------------
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o", 0x7ffec38f7370, 1024)                      = -1 EINVAL (Invalid argument)
readlinkat(AT_FDCWD, "/o/foo", 0x7ffec38f74d0, 1024)                  = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH)  = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o", 0x7ffec38f72c0, 1024)                      = -1 EINVAL (Invalid argument)
readlinkat(AT_FDCWD, "/o/foo", 0x7ffec38f7420, 1024)                  = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH)  = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC)                    = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o/.#foo", 0x7ffec38f13e8, 8193)                = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                      = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", W_OK, AT_EACCESS)                      = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                      = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o/foo", 0x7ffec38f7470, 1024)                  = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffec38f7750, 0)                     = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffec38f77f0, 0)                     = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo,v", F_OK, AT_EACCESS)                    = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffec38f5860, 0)                     = -1 ENOENT (No such file or directory)
symlink   ("[email-masked]:1723847375", "/o/.#foo")                 = -1 EIO (Input/output error)
readlinkat(AT_FDCWD, "/o/.#foo", 0x7ffec38f5ad8, 8193)                = -1 EINVAL (Invalid argument)
openat    (AT_FDCWD, "/o/.#foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC)       = 12
read      (12, "", 8193)                                              = 0
close     (12)                                                        = 0
unlink    ("/o/.#foo")                                                = 0
-------------------------------------------------- 8< ----------

And this is strace when I find-file and then save-buffer:

---------- >8 --------------------------------------------------
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o", 0x7ffe65452010, 1024)                           = -1 EINVAL (Invalid argument)
readlinkat(AT_FDCWD, "/o/foo", 0x7ffe65452170, 1024)                       = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH)       = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o", 0x7ffe65451f60, 1024)                           = -1 EINVAL (Invalid argument)
readlinkat(AT_FDCWD, "/o/foo", 0x7ffe654520c0, 1024)                       = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH)       = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC)                         = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o/.#foo", 0x7ffe6544c088, 8193)                     = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", W_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
readlinkat(AT_FDCWD, "/o/foo", 0x7ffe65452110, 1024)                       = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffe654523f0, 0)                          = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffe65452490, 0)                          = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo,v", F_OK, AT_EACCESS)                         = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffe65450500, 0)                          = -1 ENOENT (No such file or directory)
symlink   ("[email-masked]:1723847375", "/o/.#foo")                      = -1 EIO (Input/output error)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffe65452690, 0)                          = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo,v", F_OK, AT_EACCESS)                         = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY)      = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", F_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
faccessat2(AT_FDCWD, "/o/foo", W_OK, AT_EACCESS)                           = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH)       = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/o/foo", 0x7ffe6544ff80, 0)                          = -1 ENOENT (No such file or directory)
symlink   ("[email-masked]:1723847375", "/o/.#foo")                      = -1 EEXIST (File exists)
readlinkat(AT_FDCWD, "/o/.#foo", 0x7ffe65450078, 8193)                     = -1 EINVAL (Invalid argument)
openat    (AT_FDCWD, "/o/.#foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC)            = 12
read      (12, "", 8193)                                                   = 0
close     (12)                                                             = 0
unlink    ("/o/.#foo")                                                     = 0
symlink   ("[email-masked]:1723847375", "/o/.#foo")                      = -1 EIO (Input/output error)
openat    (AT_FDCWD, "/o/foo", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666)   = 12
write     (12, "ao sneuhta soneht sanoteu snothe"..., 33)                  = 33
close     (12)                                                             = 0
newfstatat(AT_FDCWD, "/o/foo", {st_mode=S_IFREG|0600, st_size=33, ...}, 0) = 0
readlinkat(AT_FDCWD, "/o/.#foo", 0x7ffe65450028, 8193)                     = -1 ENOENT (No such file or directory)
openat    (AT_FDCWD, "/o/foo", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH)       = 12
close     (12)                                                             = 0
-------------------------------------------------- 8< ----------

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»