-
Notifications
You must be signed in to change notification settings - Fork 18
fix(ns-ha): added locking mechanism on switch #1548
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
Open
Tbaile
wants to merge
3
commits into
main
Choose a base branch
from
ha-switch-locking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/sh | ||
| # | ||
| # Copyright (C) 2026 Nethesis S.r.l. | ||
| # SPDX-License-Identifier: GPL-2.0-only | ||
| # | ||
| # Acquire a global serialization lock for keepalived state-transition events | ||
| # (NOTIFY_MASTER, NOTIFY_BACKUP, NOTIFY_FAULT, NOTIFY_STOP) to prevent | ||
| # concurrent hotplug chains from racing when keepalived transitions happen in | ||
| # quick succession. | ||
| # | ||
| # The lock is released by 999-unlock at the end of the hotplug chain. | ||
| # Because hotplug-call sources each script in a subshell, a flag file is used | ||
| # to communicate whether the lock was actually acquired to 999-unlock. | ||
| # | ||
| # On timeout (60 s) the event proceeds with a warning rather than being dropped, | ||
| # to avoid leaving the system in an inconsistent state. | ||
|
|
||
| case "$ACTION" in | ||
| NOTIFY_MASTER|NOTIFY_BACKUP|NOTIFY_FAULT|NOTIFY_STOP) ;; | ||
| *) return 0 2>/dev/null || exit 0 ;; | ||
| esac | ||
|
|
||
| LOCKFILE="/var/lock/keepalived-hotplug.lock" | ||
| ACQUIRED_FLAG="/var/lock/keepalived-hotplug-acquired" | ||
| TIMEOUT=60 | ||
| elapsed=0 | ||
|
|
||
| while [ "$elapsed" -lt "$TIMEOUT" ]; do | ||
| if lock -n "$LOCKFILE" > /dev/null 2>&1; then | ||
| touch "$ACQUIRED_FLAG" | ||
| return 0 2>/dev/null || exit 0 | ||
| fi | ||
gsanchietti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sleep 1 | ||
| elapsed=$((elapsed + 1)) | ||
gsanchietti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| done | ||
|
|
||
| logger -t ns-ha "WARNING: lock timeout after ${TIMEOUT}s waiting for previous $ACTION event to complete, proceeding anyway" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/sh | ||
| # | ||
| # Copyright (C) 2026 Nethesis S.r.l. | ||
| # SPDX-License-Identifier: GPL-2.0-only | ||
| # | ||
| # Release the global keepalived hotplug lock acquired by 00-lock. | ||
| # Only acts when the flag file created by 00-lock is present — this avoids | ||
| # incorrectly releasing a lock held by a concurrent event in the rare case | ||
| # where 00-lock timed out and proceeded without acquiring the lock. | ||
|
|
||
| case "$ACTION" in | ||
| NOTIFY_MASTER|NOTIFY_BACKUP|NOTIFY_FAULT|NOTIFY_STOP) ;; | ||
| *) return 0 2>/dev/null || exit 0 ;; | ||
| esac | ||
|
|
||
| LOCKFILE="/var/lock/keepalived-hotplug.lock" | ||
| ACQUIRED_FLAG="/var/lock/keepalived-hotplug-acquired" | ||
|
|
||
| if [ -f "$ACQUIRED_FLAG" ]; then | ||
| rm -f "$ACQUIRED_FLAG" | ||
gsanchietti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lock -u "$LOCKFILE" | ||
gsanchietti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.