[jcifs] bugs in JCIFS 1.2.9
Michael B Allen
mba2000 at ioplex.com
Wed Nov 8 18:03:42 GMT 2006
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/
More information about the jcifs
mailing list