Skip to content

Commit

Permalink
Fix potential deadlock on helmfile command failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Jul 22, 2020
1 parent 1a477d9 commit c26ba83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ${DIST_PATH}/${PLUGIN_NAME}: ${GO_FILES}
build: ${DIST_PATH}/${PLUGIN_NAME}

.PHONY: install
install: build
install: clean build
mkdir -p $(PLUGIN_PATH); \
rm -rf $(PLUGIN_PATH)/${PLUGIN_NAME}; \
install -m 0755 $(DIST_PATH)/${PLUGIN_NAME} $(PLUGIN_PATH)/${PLUGIN_NAME}
Expand Down
7 changes: 3 additions & 4 deletions pkg/tfhelmfile/resource_release_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ func createRs(fs *ReleaseSet, d *schema.ResourceData, meta interface{}, stack []
d.MarkNewResource()
//obtain exclusive lock
helmfileMutexKV.Lock(releaseSetMutexKey)
defer helmfileMutexKV.Unlock(releaseSetMutexKey)

state := NewState()
st, err := runCommand(cmd, state, false)
if err != nil {
return err
}
helmfileMutexKV.Unlock(releaseSetMutexKey)

//create random uuid for the id
id := xid.New().String()
Expand Down Expand Up @@ -310,6 +310,7 @@ func diffRs(fs *ReleaseSet, d *schema.ResourceDiff, meta interface{}) error {

//obtain exclusive lock
helmfileMutexKV.Lock(releaseSetMutexKey)
defer helmfileMutexKV.Unlock(releaseSetMutexKey)

state := NewState()
newState, err := runCommand(cmd, state, true)
Expand All @@ -321,7 +322,6 @@ func diffRs(fs *ReleaseSet, d *schema.ResourceDiff, meta interface{}) error {

output := newState.Output

helmfileMutexKV.Unlock(releaseSetMutexKey)
log.Printf("[DEBUG] output:|%v|", output)
log.Printf("[DEBUG] new output:|%v|", newState.Output)

Expand Down Expand Up @@ -355,6 +355,7 @@ func updateRs(fs *ReleaseSet, d *schema.ResourceData, meta interface{}, stack []

//obtain exclusive lock
helmfileMutexKV.Lock(releaseSetMutexKey)
defer helmfileMutexKV.Unlock(releaseSetMutexKey)

state := NewState()
st, err := runCommand(cmd, state, false)
Expand All @@ -365,8 +366,6 @@ func updateRs(fs *ReleaseSet, d *schema.ResourceData, meta interface{}, stack []

SetApplyOutput(d, st.Output)

helmfileMutexKV.Unlock(releaseSetMutexKey)

//if err := read(d, meta, stack); err != nil {
// return err
//}
Expand Down

0 comments on commit c26ba83

Please sign in to comment.