Skip to content

fix(engine): throw OptimisticLockingException when process instance vanished - #4018

Open
shardtVLH wants to merge 2 commits into
operaton:mainfrom
shardtVLH:fix/engine-ole-on-deleted-process-instance
Open

shardtVLH wants to merge 2 commits into
operaton:mainfrom
shardtVLH:fix/engine-ole-on-deleted-process-instance

Conversation

@shardtVLH

@shardtVLH shardtVLH commented Oct 30, 2026 •

Copy link
Copy Markdown

Summary

Fixes #4017.

ExecutionEntity.ensureExecutionTreeInitialized threw a NullPointerException when the process
instance had been deleted by a concurrent transaction after the current execution was loaded
(e.g. a timer job inside an embedded subprocess while the process instance is deleted). The
execution tree query returns no rows, so no process instance execution is found. With
executionTreePrefetchEnabled=false, getProcessInstance() returned null instead and the NPE
occurred later in the caller.

Both paths now throw an OptimisticLockingException (new ENGINE-03111 in EnginePersistenceLogger).
The failed job handling then skips the job that no longer exists instead of creating an incident.
OLEs do not decrement job retries.

Changes

  • ExecutionEntity.ensureExecutionTreeInitialized: throw OptimisticLockingException if no process
    instance execution is found
  • ExecutionEntity.ensureProcessInstanceInitialized: same when prefetch is disabled and the process
    instance is not found
  • EnginePersistenceLogger.processInstanceDeletedConcurrently (code 111)
  • CompetingProcessInstanceDeletionTest (each test with prefetch enabled and disabled):
    • loads the timer's execution in a controllable command, deletes the process instance from the
      test thread, then loads the process instance
    • executes the timer job via ExecuteJobHelper after loading its execution, deletes the process
      instance concurrently, and checks that the job fails with an OLE without creating an incident

Testing

  • New tests fail without the fix with the reported NullPointerException and pass with it
  • mvn -pl engine test -Dtest=org.operaton.bpm.engine.test.concurrency.*Test: 69 tests, 0 failures
  • test.bpmn.** and test.api.runtime.** with executionTreePrefetchEnabled=false in the test
    configuration (local run, not committed): 3499 tests, 1 failure (SignalEventConcurrencyTest), which also fails without this change

🤖 Generated with Claude Code

@github-actions github-actions Bot added lang:java Pull requests that update Java code scope:core-api Changes to the core API: engine, dmn-engine, feel-engine, REST API, OpenAPI scope:tests Changes affecting only test code fix labels Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @shardtVLH! 🎉

Thanks for opening your first pull request. We really appreciate it.

👉 Please confirm by writing this comment that your contribution and following ones comply with the Apache License 2.0 and the Code of Conduct:

I confirm that my contribution and following ones comply with the Apache License 2.0 and the Code of Conduct.

Consider adding a star ⭐️ to the repository if you like it, we appreciate that.

Contributors will be added to the release notes of the next release.

- ensureExecutionTreeInitialized throws OptimisticLockingException instead of
  NullPointerException when the process instance was deleted concurrently
- job executor retries without decrementing retries and skips the deleted job
- add concurrency test with timer inside embedded subprocess

related to operaton#4017

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shardtVLH
shardtVLH force-pushed the fix/engine-ole-on-deleted-process-instance branch from 4d158b9 to bc1bc01 Compare October 30, 2026 17:02
@javahippie

Copy link
Copy Markdown
Contributor

Hi @shardtVLH, thanks a lot for the report and this fix! I'll look into it, much appreciated

@javahippie javahippie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the reproducer test!

No breaking change from my side: no public signatures change, and the new branch only replaces a path that always threw an NPE before. The visible effects (no incident, no retry decrement, DEBUG instead of ERROR logging, OLE error code via REST) are the intended behavior.

A few remarks:

  1. Non-prefetch path: With executionTreePrefetchEnabled=false, ensureProcessInstanceInitialized uses findExecutionById(processInstanceId), which returns null for a deleted process instance. The NPE then occurs later in the caller of getProcessInstance(). Could you handle this path the same way, so the behavior does not depend on configuration?
  2. Test scope: The test verifies the exception type. The PR description also states that retries are not decremented and no incident is created. A test via job execution would cover that, if feasible.
  3. Nit: Static import order in the test (org.assertj before org.operaton). Running .devenv/scripts/maintenance/code-cleanup.sh should fix this.

- ensureProcessInstanceInitialized throws OptimisticLockingException when
  the process instance is not found and execution tree prefetch is disabled
- run the deletion test with execution tree prefetch enabled and disabled
- add test that executes the timer job with failed job handling and checks
  that the deleted job causes no incident

related to operaton#4017

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shardtVLH

Copy link
Copy Markdown
Author

Thanks for the review! I pushed a follow-up commit:

  1. Non-prefetch path: ensureProcessInstanceInitialized now throws the same OptimisticLockingException (ENGINE-03111) when findExecutionById(processInstanceId) returns null with executionTreePrefetchEnabled=false. Both tests run with prefetch enabled and disabled. Without the fix, the disabled variant fails with the NPE you described (getProcessInstance() returns null in PvmExecutionImpl#getDelayedEvents).
  2. Test scope: The new test shouldNotCreateIncidentWhenProcessInstanceIsDeletedDuringJobExecution executes the timer job via ExecuteJobHelper.executeJob, including the failed job handling. The job's execution is loaded before the concurrent deletion. The test checks that the failure is an OLE, the job is gone, and there is no runtime or historic incident. The retry count can't be observed directly in this scenario, because the deletion also removes the job: FailedJobListener skips the missing job, and JobRetryCmd already excludes OLEs from decrementing retries.
  3. Import order: As far as I can tell, the current order follows the layout in rewrite.yml and CONTRIBUTING.md (import static org.operaton.* before import static all other imports), and other tests in the concurrency package use the same order. Happy to change it if I misread the layout.

ensureParentInitialized follows the same pattern for parentId when prefetch is disabled. I left it out to keep this PR focused, but I can add the same check if you prefer.

@shardtVLH

Copy link
Copy Markdown
Author

I confirm that my contribution and following ones comply with the Apache License 2.0 and the Code of Conduct.

@shardtVLH

Copy link
Copy Markdown
Author

Hi @javahippie, friendly ping: I addressed your review points in 5e46da0 (non-prefetch path and job-based test). CI is green and the branch merges cleanly into current main. Let me know if anything else is needed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix lang:java Pull requests that update Java code scope:core-api Changes to the core API: engine, dmn-engine, feel-engine, REST API, OpenAPI scope:tests Changes affecting only test code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException instead of OptimisticLockingException when the process instance is deleted while a job loads the execution tree

2 participants