[ https://issues.apache.org/jira/browse/FLINK-24294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17432327#comment-17432327 ]
Chesnay Schepler commented on FLINK-24294: ------------------------------------------ Isn't this something where the guava Closer can help? You can have a single try-catch block, each resource being created is added to the closer, on exception you close the closer which takes care of everything. > 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)