File tree Expand file tree Collapse file tree
spec/unit/lib/temporal/workflow Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,19 @@ def complete_task(commands, query_results)
139139 binary_checksum : binary_checksum ,
140140 query_results : query_results
141141 )
142+ rescue StandardError => error
143+ # We rescue the error here to avoid failing the task in the process
144+ # function above. One common cause of errors here is if the current
145+ # workflow task is invalidated by a concurrent signal arriving while it
146+ # tries to complete the workflow. In this case we do not need to and
147+ # should not fail the workflow task.
148+ #
149+ # Not failing the workflow task will still result it being retried after
150+ # a delay which is the behavior we'd want in cases like the above but
151+ # also for ephemeral issues like network outages.
152+ Temporal . logger . error ( "Unable to complete the workflow task" , metadata . to_h . merge ( error : error . inspect ) )
153+
154+ Temporal ::ErrorHandler . handle ( error , config , metadata : metadata )
142155 end
143156
144157 def complete_query ( result )
Original file line number Diff line number Diff line change 212212 end
213213 end
214214
215+ context 'when recording the workflow task complete fails' do
216+ let ( :exception ) { GRPC ::InvalidArgument . new ( 'workflow task could not be completed' ) }
217+
218+ before { allow ( connection ) . to receive ( :respond_workflow_task_completed ) . and_raise ( exception ) }
219+
220+ it 'does not try to fail the workflow task' do
221+ subject . process
222+
223+ expect ( connection ) . to_not have_received ( :respond_workflow_task_failed )
224+ end
225+
226+ it 'calls error_handlers' do
227+ reported_error = nil
228+ reported_metadata = nil
229+
230+ config . on_error do |error , metadata : nil |
231+ reported_error = error
232+ reported_metadata = metadata
233+ end
234+
235+ subject . process
236+
237+ expect ( reported_error ) . to be_an_instance_of ( GRPC ::InvalidArgument )
238+ expect ( reported_metadata ) . to be_an_instance_of ( Temporal ::Metadata ::WorkflowTask )
239+ end
240+ end
241+
215242 context 'when workflow task raises an exception' do
216243 let ( :exception ) { StandardError . new ( 'workflow task failed' ) }
217244
You can’t perform that action at this time.
0 commit comments