-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/commonio: make lock failures more detailed #562
lib/commonio: make lock failures more detailed #562
Conversation
This tweaks the database locking logic so that failures in the link-checking paths are more detailed. The rationale for this is that I've experienced a non-deterministic bug which seems to be coming from this logic, and I'd like to get more details about the actual failing condition.
(void) fprintf (shadow_logfd, | ||
"%s: %s file stat error: %s\n", | ||
shadow_progname, file, strerror (errno)); | ||
} | ||
return 0; | ||
} | ||
|
||
if (sb.st_nlink != 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't yet managed to reproduce the failure in a controlled environment, but I'm suspicious of this st_nlink
check.
In particular, I think it is theoretically possible on a multi-processor system to race the inode update and observe a stale link-count of 1
here after the link()
call succeeded.
I've seen other comments hinting at similar caching effects, e.g. https://github.com/miquels/liblockfile/blob/v1.17/lockfile.c#L319-L320.
What is this check actually meant to protect against? Would it be possible to safely drop it? Or maybe perform a fsync()
on the file before this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If two processes are calling commonio_lock() at the same time, the first will link %s to %s.$pid , causing %s to have link count2; then the second will link %s to %s.pid2, causing %s to have link count 3. (either $pid or $pid2 could end up finding the link count 3, or both).
I would be very surprised if the kernel's vs code was keeping the link count high, causing a race, but your results are interesting. One suspect would be overlay, if you're using that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, but here the file-linking goes in the other direction, i.e. link(dbname.pid, dbname.lock)
will create dbname.lock
as a new name for the existing dbname.pid
.
At that point a second call like link(dbname.pid2, dbname.lock)
will directly fail with EEXIST
if the .lock
file already exists, without even reaching this point.
I don't think the link count here could ever reach anything greater than 2
. On the other hand I think a (wrong/cached) value of 1
could be observed in some situations.
Yes it is happening in a bit of complex environment with bindmounts and overlays involved, but I suspect the real culprit is some kind of weakly-synchronized caching on SMP machines.
@hallyn while we aren't fully aligned on where to pinpoint the real issue and how to fix it, I think this logging-only PR should be safe to land without introducing further havoc and may help shedding some light on the low-level behavior at play. Could you maybe review/merge this? |
Yes looks good, thanks. |
This tweaks the database locking logic so that failures in the
link-checking paths are more detailed.
The rationale for this is that I've experienced a non-deterministic
bug which seems to be coming from this logic, and I'd like to get
more details about the actual failing condition.
Ref: coreos/fedora-coreos-tracker#1250