Skip to content

Commit

Permalink
Allow double unresolve & Fix missed lock (#16)
Browse files Browse the repository at this point in the history
* Allow double unresolve

* Lock mermaid call

This fixes rare concurrent map accesses

* Prevent resolving after unresolving
  • Loading branch information
jaredoconnell committed Jun 21, 2024
1 parent a3d8f17 commit 982f157
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type directedGraph[NodeType any] struct {
var errorPathRegex, _ = regexp.Compile(`\.(?:error|crashed|failed|deploy_failed)$`)

func (d *directedGraph[NodeType]) Mermaid() string {
d.lock.Lock()
defer d.lock.Unlock()

result := []string{
"%% Mermaid markdown workflow",
"flowchart LR",
Expand Down Expand Up @@ -293,8 +296,10 @@ func (n *node[NodeType]) resolveNode(newStatus ResolutionStatus) error {
return ErrNodeDeleted{n.id}
}
if n.status != Waiting {
if n.status == Resolved || n.status == Unresolvable {
if n.status == Resolved || n.status == Unresolvable && newStatus != Unresolvable {
return ErrNodeResolutionAlreadySet{n.id, n.status, newStatus}
} else if n.status == Unresolvable {
return nil // Allow nodes to be unresolved multiple times. But no processing is required.
} else {
return ErrNodeResolutionUnknown{n.id, n.status}
}
Expand Down

0 comments on commit 982f157

Please sign in to comment.