Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DFF19200BA7 for ; Fri, 21 Oct 2016 16:35:01 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DE897160AE8; Fri, 21 Oct 2016 14:35:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D93C5160AF2 for ; Fri, 21 Oct 2016 16:35:00 +0200 (CEST) Received: (qmail 7652 invoked by uid 500); 21 Oct 2016 14:34:59 -0000 Mailing-List: contact issues-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list issues@karaf.apache.org Received: (qmail 7285 invoked by uid 99); 21 Oct 2016 14:34:59 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Oct 2016 14:34:59 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id DFCD72C0D52 for ; Fri, 21 Oct 2016 14:34:58 +0000 (UTC) Date: Fri, 21 Oct 2016 14:34:58 +0000 (UTC) From: "Frederic ARNOUD (JIRA)" To: issues@karaf.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (KARAF-4802) Auto Deploy does not release resource MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 21 Oct 2016 14:35:02 -0000 [ https://issues.apache.org/jira/browse/KARAF-4802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Frederic ARNOUD updated KARAF-4802: ----------------------------------- Description: In org.apache.karaf.deployer.blueprint-4.0.7-sources.jar: org/apache/karaf/deployer/blueprint/BlueprintTransformer.java:94: {{url.openConnection().getLastModified()}} => call {{sun.net.www.protocol.file.FileURLConnection#getLastModified()}} => call {{sun.net.www.protocol.file.FileURLConnection#initializeHeaders()}} => call {{sun.net.www.protocol.file.FileURLConnection#connect()}} line 57: {{this.connected}} is {{false}} line 61: {{this.isDirectory}} is {{false}} *Here they open the input stream:* line 69: open input stream and keep it in this.is _Note:_ Bad code at line (since they try to open the stream): sun/net/www/protocol/file/FileURLConnection.java:90 with a nice empty try/catch! AFAIK, there's no way to know if stream was open or not. I checked {{HttpURLConnection}}, it does the same (and {{HttpsURLConnection}} also). *IMHO you should add a function like this one:* {code:java} protected static long getLastModified(URL url) throws IOException { URLConnection urlConnection = url.openConnection(); try(InputStream is = urlConnection.getInputStream()) { return urlConnection.getLastModified(); } } {code} To avoid risk to open remote stream twice, I did this in my code (in function similar to {{transform(URL, OutputStream)}}): {code:java} final URLConnection urlConnection = url.openConnection(); // keep original last modification date final long lastModified = urlConnection.getLastModified(); try (InputStream in = urlConnection.getInputStream()) { source = readAllBytes(in); } {code} *Note:* Since no object reference the InputStream, InputStream class will automatically close the stream while processing the finalization. Before this process, we cannot delete file in deploy directory. (sorry I did not find component for this class) Same issue should appear in other deployer (not checked). was: In org.apache.karaf.deployer.blueprint-4.0.7-sources.jar: org/apache/karaf/deployer/blueprint/BlueprintTransformer.java:94: {{url.openConnection().getLastModified()}} => call {{sun.net.www.protocol.file.FileURLConnection#getLastModified()}} => call {{sun.net.www.protocol.file.FileURLConnection#initializeHeaders()}} => call {{sun.net.www.protocol.file.FileURLConnection#connect()}} line 57: {{this.connected}} is {{false}} line 61: {{this.isDirectory}} is {{false}} *Here they open the input stream:* line 69: open input stream and keep it in this.is _Note:_ Bad code at line (since they try to open the stream): sun/net/www/protocol/file/FileURLConnection.java:90 with a nice empty try/catch! AFAIK, there's no way to know if stream was open or not. I checked {{HttpURLConnection}}, it does the same (and {{HttpsURLConnection}} also). *IMHO you should add a function like this one:* {{ protected static long getLastModified(URL url) throws IOException { URLConnection urlConnection = url.openConnection(); try(InputStream is = urlConnection.getInputStream()) { return urlConnection.getLastModified(); } } }} To avoid risk to open remote stream twice, I did this in my code (in function similar to {{transform(URL, OutputStream)}}): {{ final URLConnection urlConnection = url.openConnection(); // keep original last modification date final long lastModified = urlConnection.getLastModified(); try (InputStream in = urlConnection.getInputStream()) { source = readAllBytes(in); } }} *Note:* Since no object reference the InputStream, InputStream class will automatically close the stream while processing the finalization. Before this process, we cannot delete file in deploy directory. (sorry I did not find component for this class) Same issue should appear in other deployer (not checked). > Auto Deploy does not release resource > ------------------------------------- > > Key: KARAF-4802 > URL: https://issues.apache.org/jira/browse/KARAF-4802 > Project: Karaf > Issue Type: Bug > Components: karaf-core > Affects Versions: 4.0.5, 4.0.7 > Environment: JDK 1.8.0_102 / Win10 (x64) > Reporter: Frederic ARNOUD > Labels: leak > Original Estimate: 2h > Remaining Estimate: 2h > > In org.apache.karaf.deployer.blueprint-4.0.7-sources.jar: > org/apache/karaf/deployer/blueprint/BlueprintTransformer.java:94: > {{url.openConnection().getLastModified()}} > => call {{sun.net.www.protocol.file.FileURLConnection#getLastModified()}} > => call {{sun.net.www.protocol.file.FileURLConnection#initializeHeaders()}} > => call {{sun.net.www.protocol.file.FileURLConnection#connect()}} > line 57: {{this.connected}} is {{false}} > line 61: {{this.isDirectory}} is {{false}} > *Here they open the input stream:* > line 69: open input stream and keep it in this.is > _Note:_ > Bad code at line (since they try to open the stream): > sun/net/www/protocol/file/FileURLConnection.java:90 with a nice empty try/catch! > AFAIK, there's no way to know if stream was open or not. > I checked {{HttpURLConnection}}, it does the same (and {{HttpsURLConnection}} also). > *IMHO you should add a function like this one:* > {code:java} > protected static long getLastModified(URL url) throws IOException { > URLConnection urlConnection = url.openConnection(); > try(InputStream is = urlConnection.getInputStream()) { > return urlConnection.getLastModified(); > } > } > {code} > To avoid risk to open remote stream twice, I did this in my code (in function similar to {{transform(URL, OutputStream)}}): > {code:java} > final URLConnection urlConnection = url.openConnection(); > // keep original last modification date > final long lastModified = urlConnection.getLastModified(); > try (InputStream in = urlConnection.getInputStream()) { > source = readAllBytes(in); > } > {code} > *Note:* > Since no object reference the InputStream, InputStream class will automatically close the stream while processing the finalization. > Before this process, we cannot delete file in deploy directory. > (sorry I did not find component for this class) > Same issue should appear in other deployer (not checked). -- This message was sent by Atlassian JIRA (v6.3.4#6332)