Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-24294

Resources leak in the StreamTask constructor

    XMLWordPrintableJSON

Details

    Description

      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:
        StreamTask task = new StreamTask(); //no leaks if it fails
        try { 
          task.init();
          ....
        } finally {
          task.cleanUp();
        }
        
      • 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)

      Attachments

        Issue Links

          Activity

            People

              akalashnikov Anton Kalashnikov
              akalashnikov Anton Kalashnikov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: