[ 
https://issues.apache.org/jira/browse/FLINK-24294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Anton Kalashnikov updated FLINK-24294:
--------------------------------------
    Comment: was deleted

(was: It is not easy because the easiest way to do so is to surround all 
resources allocation with try-catch block and if something goes wrong just 
close them before leaving the method. But we don't really know where exactly we 
failed so we need to check every resource at least for null and only then close 
it which lead to a high number of null-check condition and also it is not clear 
how to guarantee that the newly added resources will be handled at the same 
way. 
We also can surround every resource with try-catch block but it is even more 
tricky because for example  RecordWriters are collected to the list and if 
something happens when the list isn't empty we should close all RecordWriters 
correctly.

In conclusion, it is not a difficult problem but it is something that we should 
think about how to do it correctly.)

> Resources leak in the StreamTask constructor
> --------------------------------------------
>
>                 Key: FLINK-24294
>                 URL: https://issues.apache.org/jira/browse/FLINK-24294
>             Project: Flink
>          Issue Type: Bug
>          Components: Runtime / Task
>    Affects Versions: 1.14.0
>            Reporter: Anton Kalashnikov
>            Priority: Major
>
> Since we are initializing a lot of resources in the StreamTask constructor 
> like RecordWriter, timerServices, etc. it is possible that some of these 
> resources remain open if the exception happens below the initialization in 
> the same constructor.
> So in my opinion, we have two choices here: 
> * Avoiding allocation of resources in the constructor which allows us to do 
> something like:
> {noformat}
> StreamTask task = new StreamTask(); //no leaks if it fails
> try { 
>   task.init();
>   ....
> } finally {
>   task.cleanUp();
> }
> {noformat}
> *  or we can rewrite a code in such a way that exception in any 
> constructor(ex. StreamTask) guarantee releasing the earlier allocated 
> resources in this constructor. But it is not so easy to implement(see. 
> initialization of recordWriter in StreamTask constructor)
> So perhaps it makes sense to separate creating object from 
> initialization(allocation resources)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to