Return-Path: X-Original-To: apmail-cxf-issues-archive@www.apache.org Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DD9EC98E7 for ; Tue, 5 Jun 2012 07:59:33 +0000 (UTC) Received: (qmail 71229 invoked by uid 500); 5 Jun 2012 07:59:33 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 71108 invoked by uid 500); 5 Jun 2012 07:59:32 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 71041 invoked by uid 99); 5 Jun 2012 07:59:31 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2012 07:59:31 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id D9ACD14001F for ; Tue, 5 Jun 2012 07:59:30 +0000 (UTC) Date: Tue, 5 Jun 2012 07:59:30 +0000 (UTC) From: =?utf-8?Q?Gon=C3=A7alo_Rodrigues_=28JIRA=29?= To: issues@cxf.apache.org Message-ID: <181478980.38511.1338883170895.JavaMail.jiratomcat@issues-vm> In-Reply-To: <625322576.33635.1338810514617.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Updated] (CXF-4356) Temp file deleted before returning the stream in CachedOutputStream MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CXF-4356?page=3Dcom.atlassian.= jira.plugin.system.issuetabpanels:all-tabpanel ] Gon=C3=A7alo Rodrigues updated CXF-4356: ----------------------------------- Description:=20 I=E2=80=99m implementing a web service to upload files (from 120 Kb to 1 Mb= ). Most of the time everything works fine, but sometimes (randomly) the upl= oaded file is empty (size =3D=3D 0) in the target platform.=20 After some debugging I found that the problem comes from the temp file crea= ted by the {{CachedOutputStream}} that is deleted during the process of get= ting the cached stream. In fact, {{maybeDeleteTempFile}} is called before {= {getInputStream}} which returns an empty {{LoadingByteArrayOutputStream}}. = The {{finalize}} method of {{FileInputStream}} calls its {{close}} method w= hich is overridden in {{CachedOutputStream#getInputStream}} to delete the t= emp file. I tried to synchronize all the methods dealing with {{tempFile}} but it did= n=E2=80=99t resolve my problem. The stack:=20 {code} Daemon System Thread [Finalizer] (Suspended (breakpoint at line 490 in Cach= edOutputStream))=09 =09CachedOutputStream.maybeDeleteTempFile(Object) line: 490=09 =09CachedOutputStream.access$000(CachedOutputStream, Object) line: 43=09 =09CachedOutputStream$1.close() line: 469=09 =09CachedOutputStream$1(FileInputStream).finalize() line: 381=09 =09Finalizer.invokeFinalizeMethod(Object) line: not available [native metho= d]=09 =09Finalizer.runFinalizer() line: 83=09 =09Finalizer.access$100(Finalizer) line: 14=09 =09Finalizer$FinalizerThread.run() line: 160=09 {code}=20 The {{getInputStream}} method:=20 {code:java} public InputStream getInputStream() throws IOException { =09flush(); =09if (inmem) { =09=09if (currentStream instanceof LoadingByteArrayOutputStream) { =09=09=09return ((LoadingByteArrayOutputStream) currentStream).createInputS= tream(); =09=09} else if (currentStream instanceof ByteArrayOutputStream) { =09=09=09return new ByteArrayInputStream(((ByteArrayOutputStream) currentSt= ream).toByteArray()); =09=09} else if (currentStream instanceof PipedOutputStream) { =09=09=09return new PipedInputStream((PipedOutputStream) currentStream); =09=09} else { =09=09=09return null; =09=09} =09} else { =09=09try { =09=09=09FileInputStream fileInputStream =3D new FileInputStream(tempFile) = { =09=09=09=09public void close() throws IOException { =09=09=09=09=09super.close(); =09=09=09=09=09maybeDeleteTempFile(this); =09=09=09=09} =09=09=09}; =09=09=09streamList.add(fileInputStream); =09=09=09return fileInputStream; =09=09} catch (FileNotFoundException e) { =09=09=09throw new IOException("Cached file was deleted, " + e.toString()); =09=09} =09} } {code}=20 The {{maybeDeleteTempFile}} method:=20 {code:java} private void maybeDeleteTempFile(Object stream) { =09streamList.remove(stream); =09if (!inmem && tempFile !=3D null && streamList.isEmpty() && allowDeleteO= fFile) { =09=09if (currentStream !=3D null) { =09=09=09try { =09=09=09=09currentStream.close(); =09=09=09=09postClose(); =09=09=09} catch (Exception e) { =09=09=09=09//ignore =09=09=09} =09=09} =09=09tempFile.delete(); =09=09tempFile =3D null; =09=09currentStream =3D new LoadingByteArrayOutputStream(1024); =09=09inmem =3D true; =09} } {code}=20 was: Sometimes (randomly) the temp file is deleted during the process of getting= the cached stream. In fact, {{maybeDeleteTempFile}} is called before {{get= InputStream}} which returns an empty {{LoadingByteArrayOutputStream}}. The = {{finalize}} method of {{FileInputStream}} calls its {{close}} method which= is overridden in {{CachedOutputStream#getInputStream}} to delete the temp = file. I tried to synchronize all the methods dealing with {{tempFile}} but it did= n=E2=80=99t resolve my problem. The stack:=20 {code} Daemon System Thread [Finalizer] (Suspended (breakpoint at line 490 in Cach= edOutputStream))=09 =09CachedOutputStream.maybeDeleteTempFile(Object) line: 490=09 =09CachedOutputStream.access$000(CachedOutputStream, Object) line: 43=09 =09CachedOutputStream$1.close() line: 469=09 =09CachedOutputStream$1(FileInputStream).finalize() line: 381=09 =09Finalizer.invokeFinalizeMethod(Object) line: not available [native metho= d]=09 =09Finalizer.runFinalizer() line: 83=09 =09Finalizer.access$100(Finalizer) line: 14=09 =09Finalizer$FinalizerThread.run() line: 160=09 {code}=20 The {{getInputStream}} method:=20 {code:java} public InputStream getInputStream() throws IOException { =09flush(); =09if (inmem) { =09=09if (currentStream instanceof LoadingByteArrayOutputStream) { =09=09=09return ((LoadingByteArrayOutputStream) currentStream).createInputS= tream(); =09=09} else if (currentStream instanceof ByteArrayOutputStream) { =09=09=09return new ByteArrayInputStream(((ByteArrayOutputStream) currentSt= ream).toByteArray()); =09=09} else if (currentStream instanceof PipedOutputStream) { =09=09=09return new PipedInputStream((PipedOutputStream) currentStream); =09=09} else { =09=09=09return null; =09=09} =09} else { =09=09try { =09=09=09FileInputStream fileInputStream =3D new FileInputStream(tempFile) = { =09=09=09=09public void close() throws IOException { =09=09=09=09=09super.close(); =09=09=09=09=09maybeDeleteTempFile(this); =09=09=09=09} =09=09=09}; =09=09=09streamList.add(fileInputStream); =09=09=09return fileInputStream; =09=09} catch (FileNotFoundException e) { =09=09=09throw new IOException("Cached file was deleted, " + e.toString()); =09=09} =09} } {code}=20 The {{maybeDeleteTempFile}} method:=20 {code:java} private void maybeDeleteTempFile(Object stream) { =09streamList.remove(stream); =09if (!inmem && tempFile !=3D null && streamList.isEmpty() && allowDeleteO= fFile) { =09=09if (currentStream !=3D null) { =09=09=09try { =09=09=09=09currentStream.close(); =09=09=09=09postClose(); =09=09=09} catch (Exception e) { =09=09=09=09//ignore =09=09=09} =09=09} =09=09tempFile.delete(); =09=09tempFile =3D null; =09=09currentStream =3D new LoadingByteArrayOutputStream(1024); =09=09inmem =3D true; =09} } {code}=20 =20 > Temp file deleted before returning the stream in CachedOutputStream > ------------------------------------------------------------------- > > Key: CXF-4356 > URL: https://issues.apache.org/jira/browse/CXF-4356 > Project: CXF > Issue Type: Bug > Affects Versions: 2.5 > Reporter: Gon=C3=A7alo Rodrigues > > I=E2=80=99m implementing a web service to upload files (from 120 Kb to 1 = Mb). Most of the time everything works fine, but sometimes (randomly) the u= ploaded file is empty (size =3D=3D 0) in the target platform.=20 > After some debugging I found that the problem comes from the temp file cr= eated by the {{CachedOutputStream}} that is deleted during the process of g= etting the cached stream. In fact, {{maybeDeleteTempFile}} is called before= {{getInputStream}} which returns an empty {{LoadingByteArrayOutputStream}}= . The {{finalize}} method of {{FileInputStream}} calls its {{close}} method= which is overridden in {{CachedOutputStream#getInputStream}} to delete the= temp file. > I tried to synchronize all the methods dealing with {{tempFile}} but it d= idn=E2=80=99t resolve my problem. > The stack:=20 > {code} > Daemon System Thread [Finalizer] (Suspended (breakpoint at line 490 in Ca= chedOutputStream))=09 > =09CachedOutputStream.maybeDeleteTempFile(Object) line: 490=09 > =09CachedOutputStream.access$000(CachedOutputStream, Object) line: 43=09 > =09CachedOutputStream$1.close() line: 469=09 > =09CachedOutputStream$1(FileInputStream).finalize() line: 381=09 > =09Finalizer.invokeFinalizeMethod(Object) line: not available [native met= hod]=09 > =09Finalizer.runFinalizer() line: 83=09 > =09Finalizer.access$100(Finalizer) line: 14=09 > =09Finalizer$FinalizerThread.run() line: 160=09 > {code}=20 > The {{getInputStream}} method:=20 > {code:java} > public InputStream getInputStream() throws IOException { > =09flush(); > =09if (inmem) { > =09=09if (currentStream instanceof LoadingByteArrayOutputStream) { > =09=09=09return ((LoadingByteArrayOutputStream) currentStream).createInpu= tStream(); > =09=09} else if (currentStream instanceof ByteArrayOutputStream) { > =09=09=09return new ByteArrayInputStream(((ByteArrayOutputStream) current= Stream).toByteArray()); > =09=09} else if (currentStream instanceof PipedOutputStream) { > =09=09=09return new PipedInputStream((PipedOutputStream) currentStream); > =09=09} else { > =09=09=09return null; > =09=09} > =09} else { > =09=09try { > =09=09=09FileInputStream fileInputStream =3D new FileInputStream(tempFile= ) { > =09=09=09=09public void close() throws IOException { > =09=09=09=09=09super.close(); > =09=09=09=09=09maybeDeleteTempFile(this); > =09=09=09=09} > =09=09=09}; > =09=09=09streamList.add(fileInputStream); > =09=09=09return fileInputStream; > =09=09} catch (FileNotFoundException e) { > =09=09=09throw new IOException("Cached file was deleted, " + e.toString()= ); > =09=09} > =09} > } > {code}=20 > The {{maybeDeleteTempFile}} method:=20 > {code:java} > private void maybeDeleteTempFile(Object stream) { > =09streamList.remove(stream); > =09if (!inmem && tempFile !=3D null && streamList.isEmpty() && allowDelet= eOfFile) { > =09=09if (currentStream !=3D null) { > =09=09=09try { > =09=09=09=09currentStream.close(); > =09=09=09=09postClose(); > =09=09=09} catch (Exception e) { > =09=09=09=09//ignore > =09=09=09} > =09=09} > =09=09tempFile.delete(); > =09=09tempFile =3D null; > =09=09currentStream =3D new LoadingByteArrayOutputStream(1024); > =09=09inmem =3D true; > =09} > } > {code}=20 -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira