Skip to content
Snippets Groups Projects
Verified Commit be48805f authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: deadlock #4

parent 85c27d07
No related branches found
No related tags found
No related merge requests found
...@@ -7,25 +7,21 @@ import ( ...@@ -7,25 +7,21 @@ import (
"github.com/r3labs/diff/v3" "github.com/r3labs/diff/v3"
) )
func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] { func (s *Settings[C]) notifyHooks(changelog diff.Changelog) {
var (
changelog diff.Changelog
err error
)
if lock {
s.Lock()
}
defer func() {
if len(changelog) > 0 { if len(changelog) > 0 {
s.notifyPostprocessingHooks(changelog) s.notifyPostprocessingHooks(changelog)
s.notifyChangeHooks(changelog) s.notifyChangeHooks(changelog)
} }
}() }
func (s *Settings[C]) setConfigInternal(config C) (*Settings[C], diff.Changelog) {
var (
changelog diff.Changelog
err error
)
errorCount := len(s.errors) errorCount := len(s.errors)
defer func() { defer func() {
...@@ -34,21 +30,15 @@ func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] { ...@@ -34,21 +30,15 @@ func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] {
} }
}() }()
defer func() {
if lock {
s.Unlock()
}
}()
if err := validateConfig[C](config); err != nil { if err := validateConfig[C](config); err != nil {
s.errors = append(s.errors, err) s.errors = append(s.errors, err)
return s return s, changelog
} }
d, err := diff.NewDiffer() d, err := diff.NewDiffer()
if err != nil { if err != nil {
s.errors = append(s.errors, err) s.errors = append(s.errors, err)
return s return s, changelog
} }
d.ConvertCompatibleTypes = true d.ConvertCompatibleTypes = true
...@@ -57,13 +47,19 @@ func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] { ...@@ -57,13 +47,19 @@ func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] {
changelog, err = d.Diff(s.config, config) changelog, err = d.Diff(s.config, config)
if err != nil { if err != nil {
s.errors = append(s.errors, err) s.errors = append(s.errors, err)
return s return s, changelog
} }
s.config = config s.config = config
return s return s, changelog
} }
func (s *Settings[C]) SetConfig(config C) *Settings[C] { func (s *Settings[C]) SetConfig(config C) *Settings[C] {
return s.setConfigInternal(config, true) s.Lock()
c, l := s.setConfigInternal(config)
s.Unlock()
s.notifyHooks(l)
return c
} }
...@@ -7,15 +7,14 @@ import ( ...@@ -7,15 +7,14 @@ import (
"gitlab.schukai.com/oss/libraries/go/utilities/pathfinder" "gitlab.schukai.com/oss/libraries/go/utilities/pathfinder"
) )
// // Copy implements the xflags.Copyable interface. // Copy implements the xflags.Copyable interface.
func (s *Settings[C]) Copy(m map[string]any) { func (s *Settings[C]) Copy(m map[string]any) {
if s == nil { if s == nil {
panic("struct is not initialized") panic("cannot copy nil")
} }
s.Lock() s.Lock()
defer s.Unlock()
errorCount := len(s.errors) errorCount := len(s.errors)
defer func() { defer func() {
...@@ -37,6 +36,9 @@ func (s *Settings[C]) Copy(m map[string]any) { ...@@ -37,6 +36,9 @@ func (s *Settings[C]) Copy(m map[string]any) {
} }
} }
s.setConfigInternal(c, false) _, l := s.setConfigInternal(c)
s.Unlock()
s.notifyHooks(l)
} }
...@@ -3,34 +3,34 @@ ...@@ -3,34 +3,34 @@
{ {
# https://devenv.sh/packages/ # https://devenv.sh/packages/
packages = [ packages = with pkgs; [
inputs.version.defaultPackage."${builtins.currentSystem}" inputs.version.defaultPackage."${builtins.currentSystem}"
pkgs.git git
pkgs.gcc12 gcc12
pkgs.go-task go-task
pkgs.blackbox blackbox
pkgs.blackbox-terminal blackbox-terminal
pkgs.jq jq
pkgs.delve delve
pkgs.gdlv gdlv
pkgs.wget wget
pkgs.glab glab
pkgs.unixtools.xxd unixtools.xxd
pkgs.libffi libffi
pkgs.zlib zlib
pkgs.procps procps
pkgs.php81Extensions.xdebug php81Extensions.xdebug
pkgs.ranger ranger
pkgs.meld meld
pkgs.gnused gnused
pkgs.coreutils-full coreutils-full
pkgs.gnugrep gnugrep
pkgs.gnumake gnumake
pkgs.util-linux util-linux
pkgs.httpie httpie
pkgs.netcat netcat
pkgs.memcached memcached
pkgs.fd fd
]; ];
...@@ -65,7 +65,7 @@ PATH="''${PATH}":${pkgs.git}/bin/ ...@@ -65,7 +65,7 @@ PATH="''${PATH}":${pkgs.git}/bin/
PATH="''${PATH}":${pkgs.gnugrep}/bin/ PATH="''${PATH}":${pkgs.gnugrep}/bin/
PATH="''${PATH}":${inputs.version.defaultPackage."${builtins.currentSystem}"}/bin/ PATH="''${PATH}":${inputs.version.defaultPackage."${builtins.currentSystem}"}/bin/
export -f PATH export PATH
task test task test
......
...@@ -83,7 +83,6 @@ func (s *Settings[C]) servePost(w http.ResponseWriter, r *http.Request) { ...@@ -83,7 +83,6 @@ func (s *Settings[C]) servePost(w http.ResponseWriter, r *http.Request) {
} }
s.Lock() s.Lock()
defer s.Unlock()
b := s.config b := s.config
s.importStream(rs) s.importStream(rs)
...@@ -91,7 +90,9 @@ func (s *Settings[C]) servePost(w http.ResponseWriter, r *http.Request) { ...@@ -91,7 +90,9 @@ func (s *Settings[C]) servePost(w http.ResponseWriter, r *http.Request) {
x := s.config x := s.config
s.config = b s.config = b
s.setConfigInternal(x, false) _, l := s.setConfigInternal(x)
s.Unlock()
s.notifyHooks(l)
} }
......
...@@ -187,7 +187,6 @@ func (s *Settings[C]) importFiles() { ...@@ -187,7 +187,6 @@ func (s *Settings[C]) importFiles() {
func (s *Settings[C]) Import() *Settings[C] { func (s *Settings[C]) Import() *Settings[C] {
s.Lock() s.Lock()
defer s.Unlock()
errorCount := len(s.errors) errorCount := len(s.errors)
defer func() { defer func() {
...@@ -216,7 +215,9 @@ func (s *Settings[C]) Import() *Settings[C] { ...@@ -216,7 +215,9 @@ func (s *Settings[C]) Import() *Settings[C] {
x := s.config x := s.config
s.config = defaults s.config = defaults
s.setConfigInternal(x, false) _, l := s.setConfigInternal(x)
s.Unlock()
s.notifyHooks(l)
return s return s
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment