Uploaded image for project: 'Synapse'
  1. Synapse
  2. SYNAPSE-212

XSLTMediator doesn't close/delete temporary files properly

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1, NIGHTLY
    • Fix Version/s: 1.2
    • Component/s: Core
    • Labels:
      None

      Description

      When a temporary file is used for the transformation result, XSLTMediator will read it back using the following instructions:

      StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(tempTargetFile));
      result = builder.getDocumentElement();

      Since Axiom constructs the XML tree on demand, this will actually not read the entire file but only a small part of it. Also, since nobody ever closes the input stream explicitly, the file will only be closed when the FileInputStream object is garbage collected.

      Immediately after the above instructions, XSLTMediator executes the following piece of code:

      boolean deleted = tempTargetFile.delete();
      if (!deleted) {
      tempTargetFile.deleteOnExit();
      }

      Since the file is still open at that moment, on Windows platforms, the delete operation will fail. Therefore the file will not be deleted until Synapse is shut down or restarted. On Unix systems, only the directory entry will be removed, but not the inode (and the content). On these systems, the file will be deleted by the OS when the file is closed, i.e. when the FileInputStream object is garbage collected.

      This problem is not easy to solve because the input stream can't be closed inside the mediate method (the whole purpose of having a temporary file being to allow streaming). It can only be closed (and deleted) safely once the sequence containing the XSLT mediation is completed and the message has been sent. Unfortunately, there seems to be no generic mechanism in Synapse to do this. Actually what would be needed is something similar to the flowComplete method in org.apache.axis2.engine.Handler.

        Issue Links

          Activity

          Hide
          asankha Asankha C. Perera added a comment -

          postponing to fix post 1.1.1

          Show
          asankha Asankha C. Perera added a comment - postponing to fix post 1.1.1
          Hide
          veithen Andreas Veithen added a comment -

          Lowered priority from major to minor because temporary files are now deleted when the corresponding TemporaryData objects are garbage collected. This is still not optimal but should avoid resource exhaustion.

          Show
          veithen Andreas Veithen added a comment - Lowered priority from major to minor because temporary files are now deleted when the corresponding TemporaryData objects are garbage collected. This is still not optimal but should avoid resource exhaustion.
          Hide
          ruwan Ruwan Linton added a comment -

          Andreas, I think we cannot further optimize the solution to this problem. Also it is suboptimal and hence I hope we can mark this issue as fixed.. Isn't it?

          Show
          ruwan Ruwan Linton added a comment - Andreas, I think we cannot further optimize the solution to this problem. Also it is suboptimal and hence I hope we can mark this issue as fixed.. Isn't it?
          Hide
          veithen Andreas Veithen added a comment -

          The current solution is acceptable (even if not optimal). Since there doesn't seem to be a better solution, marked this issue as solved.

          Show
          veithen Andreas Veithen added a comment - The current solution is acceptable (even if not optimal). Since there doesn't seem to be a better solution, marked this issue as solved.

            People

            • Assignee:
              veithen Andreas Veithen
              Reporter:
              veithen Andreas Veithen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development