OutOfMemoryError when writing with SmbFileOutputStream

View: New views
6 Messages — Rating Filter:   Alert me  

OutOfMemoryError when writing with SmbFileOutputStream

by Krum Valkov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm trying to use jcifs 1.3.12 with business integration server to store files
in shared folders. When I use password authentication with domain, user and pass
the write method of SmbFileOutputStream creates considerable amount of new
threads that do not finish fast enough and when I try to transfer file larger
then 2 MB the transfer fails with error:
java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:597)
        at jcifs.UniAddress.lookupServerOrWorkgroup(UniAddress.java:173)
        at jcifs.UniAddress.getAllByName(UniAddress.java:290)
        at jcifs.UniAddress.getByName(UniAddress.java:245)
        at jcifs.smb.Dfs.getTrustedDomains(Dfs.java:62)
        at jcifs.smb.Dfs.resolve(Dfs.java:146)
        at jcifs.smb.SmbFile.resolveDfs(SmbFile.java:667)
        at jcifs.smb.SmbFile.send(SmbFile.java:730)
        at jcifs.smb.SmbFileOutputStream.writeDirect(SmbFileOutputStream.java:245)
        at jcifs.smb.SmbFileOutputStream.write(SmbFileOutputStream.java:216)

Is there some kind of configuration to control this?

Thanks in advice.

Regards Krum Valkov


Re: OutOfMemoryError when writing with SmbFileOutputStream

by Michael B Allen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Krum,

This is a pretty strange error. The getTrustedDomains call should only
happen once every 50 minutes and the DFS referral that's triggering it
should only happen once every 5 minutes.

Are you getting other kinds of stack traces or is the failure always
with getTrustedDomains?

Based on the limited information provided, I would say something about
the environment is wrong. What is "business integration server"?

Mike

On Fri, Oct 30, 2009 at 9:55 AM, Krum Valkov <k.valkov@...> wrote:

> Hi,
>
> I'm trying to use jcifs 1.3.12 with business integration server to store files
> in shared folders. When I use password authentication with domain, user and pass
> the write method of SmbFileOutputStream creates considerable amount of new
> threads that do not finish fast enough and when I try to transfer file larger
> then 2 MB the transfer fails with error:
> java.lang.OutOfMemoryError: unable to create new native thread
>        at java.lang.Thread.start0(Native Method)
>        at java.lang.Thread.start(Thread.java:597)
>        at jcifs.UniAddress.lookupServerOrWorkgroup(UniAddress.java:173)
>        at jcifs.UniAddress.getAllByName(UniAddress.java:290)
>        at jcifs.UniAddress.getByName(UniAddress.java:245)
>        at jcifs.smb.Dfs.getTrustedDomains(Dfs.java:62)
>        at jcifs.smb.Dfs.resolve(Dfs.java:146)
>        at jcifs.smb.SmbFile.resolveDfs(SmbFile.java:667)
>        at jcifs.smb.SmbFile.send(SmbFile.java:730)
>        at jcifs.smb.SmbFileOutputStream.writeDirect(SmbFileOutputStream.java:245)
>        at jcifs.smb.SmbFileOutputStream.write(SmbFileOutputStream.java:216)
>
> Is there some kind of configuration to control this?
>
> Thanks in advice.
>
> Regards Krum Valkov
>
>



--
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/

Re: OutOfMemoryError when writing with SmbFileOutputStream

by Krum Valkov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I managed to reproduce the error with a simple java program without using the
JBoss server. Here is the main method and the whole stack trace. I tryed to
start it few times and the time interval, before the error appears is different,
but it always shows up.

47  public static void main(String[] args)
48      throws IOException
49  {
50      int bufferSize = 1024 * 512;
51      byte[] buffer = new byte[bufferSize];
52      for (int i = 0; i < buffer.length; i++)
53      {
54          buffer[i] = (byte)(i % Byte.MAX_VALUE);
55      }
56      System.out.println("START");
57      NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(DOMAIN,
USER_NAME, PASSWORD);
58      SmbFile dir = new SmbFile(DIRECTORY, auth);
59      if (!dir.exists())
60      {
61          dir.mkdirs();
62      }
63      SmbFile file = new SmbFile(dir.getPath() + "F" +
System.currentTimeMillis(), auth);
64      if (!file.exists())
65      {
66          file.createNewFile();
67      }
68      System.out.println("SMB file " + file.getPath() + " created!");
69      SmbFileOutputStream out = new SmbFileOutputStream(file);
70      int iterations = 2000;
71      System.out.println("Start writing");
72      long startTime = System.currentTimeMillis();
73      for (int i = 0; i < iterations; i++)
74      {
75          out.write(buffer, 0, buffer.length);
76      }
77      long endTime = System.currentTimeMillis();
78      String writingTime = (endTime - startTime) / 1000 + " seconds and " +
(endTime - startTime) % 1000 + " milliseconds";
79      System.out.println("Writing finished in " + writingTime);
80  }

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new
native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:597)
        at jcifs.UniAddress.lookupServerOrWorkgroup(UniAddress.java:173)
        at jcifs.UniAddress.getAllByName(UniAddress.java:290)
        at jcifs.UniAddress.getByName(UniAddress.java:245)
        at jcifs.smb.Dfs.getTrustedDomains(Dfs.java:62)
        at jcifs.smb.Dfs.resolve(Dfs.java:146)
        at jcifs.smb.SmbFile.resolveDfs(SmbFile.java:667)
        at jcifs.smb.SmbFile.send(SmbFile.java:730)
        at jcifs.smb.SmbFileOutputStream.writeDirect(SmbFileOutputStream.java:245)
        at jcifs.smb.SmbFileOutputStream.write(SmbFileOutputStream.java:216)
        at com.seeburger.krum.test.TestFileStore.main(TestFileStore.java:75)





Re: OutOfMemoryError when writing with SmbFileOutputStream

by Krum Valkov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

When I set the jcifs.smb.client.dfs.disabled property to true the resolve method
does not call getTrustedDomains and everything is ok. Is there some case in
which this property may cause some problems?



Re: OutOfMemoryError when writing with SmbFileOutputStream

by Michael B Allen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Krum,

If you disable DFS the client will not support DFS. But even disabling
it probably is not really making everything "ok". The OOM condition is
probably not being caused by creating threads for the trusted domains
lookup. It is more likely related to some byte[] array data not being
released or something unrelated to the trusted domains lookup. It's
just that creating a thread requires a chunk of memory and so that
happens to be the moment at which you see the failure.

Please resend your test program as an attachment and without line
numbers and I will look into it.

Mike

On Mon, Nov 2, 2009 at 5:54 AM, Krum Valkov <k.valkov@...> wrote:
> Hi,
>
> When I set the jcifs.smb.client.dfs.disabled property to true the resolve method
> does not call getTrustedDomains and everything is ok. Is there some case in
> which this property may cause some problems?
>
>
>



--
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/

Re: OutOfMemoryError when writing with SmbFileOutputStream

by Krum Valkov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Mike,

Here is the program. The problem does not occur when I use local user and no domain, so the domain is important. I hope you coud find the problem.

Best regards Krum

Michael B Allen написа:
Hi Krum,

If you disable DFS the client will not support DFS. But even disabling
it probably is not really making everything "ok". The OOM condition is
probably not being caused by creating threads for the trusted domains
lookup. It is more likely related to some byte[] array data not being
released or something unrelated to the trusted domains lookup. It's
just that creating a thread requires a chunk of memory and so that
happens to be the moment at which you see the failure.

Please resend your test program as an attachment and without line
numbers and I will look into it.

Mike

On Mon, Nov 2, 2009 at 5:54 AM, Krum Valkov k.valkov@... wrote:
  
Hi,

When I set the jcifs.smb.client.dfs.disabled property to true the resolve method
does not call getTrustedDomains and everything is ok. Is there some case in
which this property may cause some problems?



    



  

import java.io.IOException;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;


/*
 * TestFileStore.java
 *
 * created at 29.10.2009 by Krum Valkov <k.valkov@...>
 *
 * $Id: eclipse-seeburger-codetemplates.xml,v 1.1 2005/03/04 15:02:28 UllrichPollaehne Exp www-data $
 *
 * Copyright (c) 2009 SEEBURGER AG, Germany. All Rights Reserved.
 */

public class TestFileStore
{
    private static final String DOMAIN = "";
    private static final String PASSWORD = "";
    private static final String USER_NAME = "";
    private static String DIRECTORY = "";


    public static void main(String[] args)
        throws IOException
    {
        int bufferSize = 1024 * 512;
        byte[] buffer = new byte[bufferSize];
        for (int i = 0; i < buffer.length; i++)
        {
            buffer[i] = (byte)(i % Byte.MAX_VALUE);
        }
        System.out.println("START");
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(DOMAIN, USER_NAME, PASSWORD);

        SmbFile dir = new SmbFile(DIRECTORY, auth);
        if (!dir.exists())
        {
            dir.mkdirs();
        }
        SmbFile file = new SmbFile(dir.getPath() + "F" + System.currentTimeMillis(), auth);
        if (!file.exists())
        {
            file.createNewFile();
        }
        System.out.println("SMB file " + file.getPath() + " created!");
        SmbFileOutputStream out = new SmbFileOutputStream(file);
        int iterations = 2000;
        System.out.println("Start writing");
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < iterations; i++)
        {
            out.write(buffer, 0, buffer.length);
        }
        long endTime = System.currentTimeMillis();
        String writingTime = (endTime - startTime) / 1000 + " seconds and " + (endTime - startTime) % 1000
                             + " milliseconds";
        System.out.println("Writing finished in " + writingTime);
    }
}