Github user StephanEwen commented on the issue:
https://github.com/apache/flink/pull/5394
I have often handled it like one of the below variants. What do you think
about that pattern?
### Variant 1: Handle interruption if still running
```java
public void run(SourceContext<T> ctx) throws Exception {
while (running) {
try {
// do stuff
Thread.sleep(20);
} catch (InterruptedException e) {
// restore interruption flag
Thread.currentThread().interrupt();
if (running) {
throw new FlinkException("interrupted while still running",
e);
}
// else fall through the loop
}
}
```
### Variant 2: Simple let InterruptedException bubble out
This variant is also fine, because the Task status is set to CANCELED
before the interruption, so any exception bubbling out be suppresses.
```java
public void run(SourceContext<T> ctx) throws Exception {
while (running) {
// do stuff
// the InterruptedException from here simply fails the execution
Thread.sleep(20);
}
}
```
---