[jcifs] bugs in JCIFS 1.2.9

Tim Struyf tim.struyf at roots.be
Wed Nov 15 14:35:36 GMT 2006


Dear,
 
This issue isnt fixed in JCIFS 1.2.10...
I still see a lot of writer threads that stay in their locked state in the new version...
 
I thinkt the w.interrupt is realy required to fix this issue...
 
see attached screenshot
 
regards,
Tim

________________________________

From: Michael B Allen [mailto:mba2000 at ioplex.com]
Sent: Mon 13/11/2006 5:40 PM
To: Tim Struyf; jcifs at lists.samba.org; contact! Support
Subject: Re: [jcifs] bugs in JCIFS 1.2.9



This has been fixed. If the copyTo0 fails a finally has been added to
guarantee files are closed. Another finally has been added to copyTo()
that guarantees that the stop write signals the WriterThread to wake up
and exit (if the WriterThread is stuck trying to read this will have no
effect, it does not use interrupt()).

Mike

On Wed, 8 Nov 2006 13:03:42 -0500
Michael B Allen <mba2000 at ioplex.com> wrote:

> Yes, I believe this is all the same bug someone reported before. The
> bug is because of a big try catch added to SmbFile.copyTo0 during some
> debugging. Try to remove/move the try catch to look like the below:
> And please let me know if it works. I'm going to do an update soon.
>
>    1972             }
>    1973         } else {
>    1974             int off;
>    1975
>    1976             try {
>    1977                 open( SmbFile.O_RDONLY, 0, ATTR_NORMAL, 0 );
>    1978                 try {
>    ....
>    2022                 dest.send( new Trans2SetFileInformation(
>    2023                         dest.fid, attributes, createTime, lastModified ),
>    2024                         new Trans2SetFileInformationResponse() );
>    2025                 dest.close( 0L );
>    2026             } catch( Exception ex ) {
>    2027                 if( log.level > 1 )
>    2028                     ex.printStackTrace( log );
>    2029             } finally { <<---- important to always close!
>    2030                 close();
>    2031             }
>    2032         }
>    2033     }
>    2034 /**
>
>
> On Wed, 8 Nov 2006 17:00:18 +0100
> "Tim Struyf" <tim.struyf at roots.be> wrote:
>
> > Dear,
> >
> > 
> >
> > I found a bug in JCIFS 1.2.9
> >
> > 
> >
> > Apparently when trying to copy a file that does not exist the
> > writerthread isn't closed.
> >
> > Thus causing problems with a lot of writerthreads that are and remain in
> > the "wait" state
> >
> > 
> >
> > For example if you execute this testcase with version 1.2.9 you will get
> > 1000 writer threads in the "wait" state
> >
> > Important is that you have a share and try to open a file that does not
> > exist, you will get a stacktrace printed in your console ... but the
> > writer thread stays open...
> >
> > 
> >
> > public class JCifsTest extends TestCase {
> >
> > public void testCopy() {
> >
> >                         for(int i = 0; i < 1000; i++) {
> >
> >                                     try {
> >
> >                                                 SmbFile file
> > = JCifsUtil.getSmbFileFor( "myComputer/someShare/fileDoesNotExist.txt"
> > );
> >
> >                                                 SmbFile to
> > = JCifsUtil.getSmbFileFor( "myComputer/someShare/fileDoesNotExist.txt");
> >
> >                                                 file.copyTo(to);
> >
> >                                     } catch (Exception e) {
> >
> >                                                 e.printStackTrace();
> >
> >                                     }
> >
> >                         }
> >
> >                         //put a breakpoint up here and see... 1000
> > writer threads waiting...
> >
> >                         System.out.println("boom!");
> >
> >             }                      
> >
> > }
> >
> > 
> >
> > I fixed this by adding a try catch clause in the copyTo method in
> > SmbFile.java
> >
> > 
> >
> >        /** copy to method.... **/
> >
> > 
> >
> >         w = new WriterThread();
> >
> >         w.setDaemon( true );
> >
> >         w.start();
> >
> >             //added a try catch block
> >
> >         try {
> >
> >                     /* Downgrade one transport to the lower of the
> > negotiated buffer sizes
> >
> >                      * so we can just send whatever is received.
> >
> >                      */
> >
> > 
> >
> >                     SmbTransport t1 = tree.session.transport;
> >
> >                     SmbTransport t2 = dest.tree.session.transport;
> >
> >            
> >
> >                     if( t1.snd_buf_size < t2.snd_buf_size ) {
> >
> >                         t2.snd_buf_size = t1.snd_buf_size;
> >
> >                     } else {
> >
> >                         t1.snd_buf_size = t2.snd_buf_size;
> >
> >                     }
> >
> >            
> >
> >                     bsize = Math.min( t1.rcv_buf_size - 70,
> > t1.snd_buf_size - 70 );
> >
> >                     b = new byte[2][bsize];
> >
> > 
> >
> >             copyTo0( dest, b, bsize, w, req, resp );
> >
> >             w.write( null, -1, null, 0 );
> >
> >        } catch (Exception e ){
> >
> >             //stop the writer thread! If we get an exception
> >
> >             e.printStackTrace();
> >
> >             w.interrupt();
> >
> >        }
> >
> > 
> >
> > 
> >
> > Another bug was already posted here.
> >
> > If you try to copy a file to a share on which you don't have access
> > rights, this fails but the writer threads don't close... also the source
> > file you are copying from cant be deleted... because its in use... (by
> > the writerthread that's locked...)
> >
> > 
> >
> > public void testCopyAndDelete() throws SmbException {
> >
> >                         for(int i = 0; i < 1000; i++) {
> >
> >                                     try {
> >
> >                                                 SmbFile file       =
> > JCifsUtil.getSmbFileFor( "myComputer/myShare/someFile.txt" );
> >
> > 
> > System.out.println(file.getUncPath() + " exists: " +  file.exists());
> >
> >                                                 SmbFile to
> > = JCifsUtil.getSmbFileFor(
> > "myComputer/ShareOnWhichIDontHaveAccessRights/someFile.txt");
> >
> > 
> > System.out.println(to.getUncPath() + " exists: "    +  to.exists());
> >
> >                                                 file.copyTo( to );
> >
> >                                                 file.delete();
> >
> >                                     } catch (Exception e) {
> >
> >                                                 e.printStackTrace();
> >
> >                                     }
> >
> >                         }
> >
> >             }
> >
> > 
> >
> > In version 1.2.9 of JCIFS this code will cause the errors described
> > above, a lot of writer threads that are locked + files that are in use,
> > and cant be deleted...
> >
> > I fixed this by changing the copyTo0 method in SmbFile.java
> >
> > 
> >
> > 
> >
> >                                                 dest.send( new
> > Trans2SetFileInformation(dest.fid, attributes, createTime, lastModified
> > ),  new Trans2SetFileInformationResponse() );
> >
> >                                                 dest.close( 0L );
> >
> >                                     } catch( Exception ex ) {
> >
> >                                                 //stop the writerthreads
> >
> >                                                 w.interrupt();
> >
> >                                                 if( log.level > 1 )
> >
> > 
> > ex.printStackTrace( log );
> >
> >                                     } finally {
> >
> >                                                 //added a finally clause
> >
> >                                                 close();
> >
> >                                     }
> >
> > Best regards,
> >
> > Tim
> >
> > groetjes,
> >
> > Tim Struyf
> > Consultant,
> >
> > Roots Software
> > Oudestraat 113 * 2630 Aartselaar * Belgium
> > Phone + 32 3 870 71 11 * Fax + 32 3 870 71 19
> > Email: tim.struyf at roots.be <mailto:tim.struyf at roots.be>
> > http://www.roots.be
> >
> > 
> >
> >
>
>
> --
> Michael B Allen
> PHP Active Directory SSO
> http://www.ioplex.com/
>


--
Michael B Allen
PHP Active Directory SSO
http://www.ioplex.com/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: jcifs_problems.gif
Type: image/gif
Size: 10928 bytes
Desc: jcifs_problems.gif
Url : http://lists.samba.org/archive/jcifs/attachments/20061115/8104fb44/jcifs_problems.gif


More information about the jcifs mailing list