markap14 opened a new pull request, #11646:
URL: https://github.com/apache/nifi/pull/11646

   # Summary
   
   [NIFI-16288](https://issues.apache.org/jira/browse/NIFI-16288)
   
   A Connector could not be stopped when one of its managed Controller Services 
never finished enabling. There are two ways a service can get into that 
situation: its `@OnEnabled` method blocks indefinitely, or its `@OnEnabled` 
method keeps throwing an Exception and the framework keeps retrying it. In 
either case the Connector stayed in `STOPPING` and its services stayed in 
`ENABLING`, and there was no way to recover other than restarting NiFi.
   
   Two things caused this:
   
   1. When a Controller Service that is `ENABLING` was asked to disable, the 
futures returned to callers waiting on enablement were never completed. Those 
callers waited on an enable attempt that was never going to finish.
   2. When a Connector was asked to stop while it was still starting, the stop 
was simply deferred until the start completed. If the start was blocked waiting 
on a Controller Service to enable, the start never completed, so the stop never 
ran.
   
   Changes in this pull request:
   
   - `ServiceStateTransition.transitionToDisabling` now completes any pending 
enable futures exceptionally with a `CancellationException` when the service 
moves from `ENABLING` to `DISABLING`, so callers waiting on enablement are 
released.
   - `StandardConnectorNode` now disables the Connector's managed Controller 
Services when a stop is requested while the Connector is still starting, so the 
startup can finish and the stop can be carried out. If disabling fails, it is 
retried.
   - Connector start and stop invocations are serialized with a lock so that a 
stop cannot complete while a start is still in flight. When a disable finishes 
while a start is still running, the disable is reasserted rather than blocking, 
because a start can begin enabling services again after an earlier disable 
completed.
   
   Tests added:
   
   - 
`StandardConnectorNodeIT.testStopConnectorWhileManagedServiceBlocksInOnEnabled` 
covers a managed Controller Service whose `@OnEnabled` method blocks.
   - 
`StandardConnectorNodeIT.testStopConnectorWhileManagedServiceKeepsFailingOnEnabled`
 covers a managed Controller Service whose `@OnEnabled` method keeps throwing 
an Exception across retries.
   - 
`TestStandardProcessScheduler.testRepeatedDisableWhileEnablingCompletesFutures` 
asserts that the enable future completes with a `CancellationException` when a 
service is disabled while enabling.
   
   Both new Connector tests were confirmed to hang and time out against the 
unmodified code, and to pass with the change in place.
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue 
created
   
   ### Pull Request Tracking
   
   - Pull Request title starts with Apache NiFi Jira issue number, such as 
`NIFI-00000`
   - Pull Request commit message starts with Apache NiFi Jira issue number, as 
such `NIFI-00000`
   - Pull request contains [commits 
signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits)
 with a registered key indicating `Verified` status
   
   ### Pull Request Formatting
   
   - Pull Request based on current revision of the `main` branch
   - Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request 
creation.
   
   ### Build
   
   - [x] Build completed using `./mvnw clean install -P contrib-check`
     - [x] JDK 21
     - [ ] JDK 25
   
   ### Licensing
   
   - [x] New dependencies are compatible with the [Apache License 
2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License 
Policy](https://www.apache.org/legal/resolved.html)
   - [x] New dependencies are documented in applicable `LICENSE` and `NOTICE` 
files
   
   ### Documentation
   
   - [x] Documentation formatting appears as expected in rendered files
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to