[jcifs] bugs in JCIFS 1.2.9

Tim Struyf tim.struyf at roots.be
Wed Nov 8 16:00:18 GMT 2006


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 

 

-------------- next part --------------
HTML attachment scrubbed and removed


More information about the jcifs mailing list