Skip to content
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

NET-1269:add mutex for upgrade #802

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion functions/mqhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var All mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
slog.Info("default message handler -- received message but not handling", "topic", msg.Topic())
}

var mNMutex = sync.Mutex{} // used to mutex functions of the interface
var mNMutex = sync.Mutex{} // used to mutex functions of the interface
var upgMutex = sync.Mutex{} // used to mutex functions of upgrade

// NodeUpdate -- mqtt message handler for /update/<NodeID> topic
func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
Expand Down Expand Up @@ -144,12 +145,14 @@ func HostPeerUpdate(client mqtt.Client, msg mqtt.Message) {
}
if vlt && config.Netclient().Host.AutoUpdate {
slog.Info("updating client to server's version", "version", peerUpdate.ServerVersion)
upgMutex.Lock()
if err := UseVersion(peerUpdate.ServerVersion, false); err != nil {
slog.Error("error updating client to server's version", "error", err)
} else {
slog.Info("updated client to server's version", "version", peerUpdate.ServerVersion)
daemon.HardRestart()
}
upgMutex.Unlock()
//daemon.Restart()
}
}
Expand Down Expand Up @@ -251,6 +254,7 @@ func HostUpdate(client mqtt.Client, msg mqtt.Message) {
slog.Warn("error checking version less than, but will proceed with upgrade", "error", err)
}
slog.Info("upgrading client to server's version", "version", sv)
upgMutex.Lock()
abhishek9686 marked this conversation as resolved.
Show resolved Hide resolved
if err := UseVersion(sv, false); err != nil {
slog.Error("error upgrading client to server's version", "error", err)
break
Expand All @@ -259,6 +263,7 @@ func HostUpdate(client mqtt.Client, msg mqtt.Message) {
if err := daemon.HardRestart(); err != nil {
slog.Error("failed to hard restart daemon", "error", err)
}
upgMutex.Unlock()
case models.JoinHostToNetwork:
commonNode := hostUpdate.Node.CommonNode
nodeCfg := config.Node{
Expand Down Expand Up @@ -552,12 +557,14 @@ func mqFallbackPull(pullResponse models.HostPull, resetInterface, replacePeers b
}
if vlt && config.Netclient().Host.AutoUpdate {
slog.Info("updating client to server's version", "version", pullResponse.ServerConfig.Version)
upgMutex.Lock()
if err := UseVersion(pullResponse.ServerConfig.Version, false); err != nil {
slog.Error("error updating client to server's version", "error", err)
} else {
slog.Info("updated client to server's version", "version", pullResponse.ServerConfig.Version)
daemon.HardRestart()
}
upgMutex.Unlock()
}
}
if pullResponse.ServerConfig.Version != server.Version {
Expand Down
Loading