@@ -2078,9 +2078,7 @@ func (s *sysDB) getEvent(ctx context.Context, input getEventInput) (any, error)
20782078 defer func () {
20792079 cond .Broadcast ()
20802080 // Clean up the condition variable after we're done, if we created it
2081- if ! loaded {
2082- s .workflowEventsMap .Delete (payload )
2083- }
2081+ s .workflowEventsMap .Delete (payload )
20842082 }()
20852083
20862084 // Check if the event already exists in the database
@@ -2090,11 +2088,13 @@ func (s *sysDB) getEvent(ctx context.Context, input getEventInput) (any, error)
20902088 row := s .pool .QueryRow (ctx , query , input .TargetWorkflowID , input .Key )
20912089 err := row .Scan (& valueString )
20922090 if err != nil && err != pgx .ErrNoRows {
2093- cond .L .Unlock ()
2091+ if ! loaded {
2092+ cond .L .Unlock ()
2093+ }
20942094 return nil , fmt .Errorf ("failed to query workflow event: %w" , err )
20952095 }
20962096
2097- if err == pgx .ErrNoRows {
2097+ if err == pgx .ErrNoRows { // this implies isLaunched is True
20982098 // Wait for notification with timeout using condition variable
20992099 done := make (chan struct {})
21002100 go func () {
@@ -2129,11 +2129,8 @@ func (s *sysDB) getEvent(ctx context.Context, input getEventInput) (any, error)
21292129 row = s .pool .QueryRow (ctx , query , input .TargetWorkflowID , input .Key )
21302130 err = row .Scan (& valueString )
21312131 if err != nil && err != pgx .ErrNoRows {
2132- cond .L .Unlock ()
21332132 return nil , fmt .Errorf ("failed to query workflow event after wait: %w" , err )
21342133 }
2135- } else {
2136- cond .L .Unlock ()
21372134 }
21382135
21392136 // Deserialize the value if it exists
0 commit comments