rkhachatryan commented on a change in pull request #16885:
URL: https://github.com/apache/flink/pull/16885#discussion_r694629870
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
##########
@@ -760,33 +763,26 @@ private void doRun() {
// make sure the user code classloader is accessible thread-locally
executingThread.setContextClassLoader(userCodeClassLoader.asClassLoader());
- FlinkSecurityManager.monitorUserSystemExitForCurrentThread();
+ TaskInvokable finalInvokable = invokable;
try {
- // Restore invokable data to the last valid state
- invokable.restore();
- } finally {
- FlinkSecurityManager.unmonitorUserSystemExitForCurrentThread();
- }
+ runWithSystemExitMonitoring(finalInvokable::restore);
- if (!transitionState(ExecutionState.INITIALIZING,
ExecutionState.RUNNING)) {
- throw new CancelTaskException();
- }
+ if (!transitionState(ExecutionState.INITIALIZING,
ExecutionState.RUNNING)) {
+ throw new CancelTaskException();
+ }
- // notify everyone that we switched to running
- taskManagerActions.updateTaskExecutionState(
- new TaskExecutionState(executionId,
ExecutionState.RUNNING));
+ // notify everyone that we switched to running
+ taskManagerActions.updateTaskExecutionState(
+ new TaskExecutionState(executionId,
ExecutionState.RUNNING));
- // Monitor user codes from exiting JVM covering user function
invocation. This can be
- // done in a finer-grained way like enclosing user callback
functions individually,
- // but as exit triggered by framework is not performed and
expected in this invoke
- // function anyhow, we can monitor exiting JVM for entire scope.
- FlinkSecurityManager.monitorUserSystemExitForCurrentThread();
- try {
- // run the invokable
- invokable.invoke();
- } finally {
- FlinkSecurityManager.unmonitorUserSystemExitForCurrentThread();
+ runWithSystemExitMonitoring(finalInvokable::invoke);
+ } catch (Throwable throwable) {
+ if (!(throwable instanceof CancelTaskException)) {
Review comment:
I have adjusted the logic so that `cancelTask()` is called from
`cleanUp()` only in exceptional case (so the old behavior is preserved).
Otherwise, `SourceFunction` gets cancelled in the normal case (which is
probably fine, but FLINK-23527 should be resolved first).
--
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]