<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dropbox Java API - java.net.SocketException: Too many open files in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58282#M1845</link>
    <description>&lt;P&gt;Below is the script we used to create a directory structure for testing.   Because Dropbox does not have any API for bulk upload, we essentially traverse the directory tree, and upload file and create directories one at a time.   The program would throw "java.net.SocketException:  Too many open files"  error.  I would say, around 20+ directory creation.  I checked out your Java API source code, my guess is that there are a few places in your DBRequestUtil.java that DropboxAPI team hasn't closed the &lt;CODE&gt;InputStream&lt;/CODE&gt; properly.  One of the example is &lt;CODE&gt;readJsonFromResponse()&lt;/CODE&gt; function call, the result is simple returned with 'return reader.readFully(body)'.  I have changed it to the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;T t = reader.readFully(body);
if ( body != null )  body.close();
return t;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;______ script for creating directories for testing ________&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/local/bin//tcsh -f
set level1 = ( a b c d e f g h i j )
set level2 = ( 1 2 3 4 5 6 7 8 9 0 )
set level3 = ( p q r s t u v w x y )
set size = 1024
set count = 128

foreach aa ( $level1 ) 
    mkdir $aa
    dd if=/dev/random of=$aa/file$aa.txt count=$count bs=$size
    foreach bb ( $level2 )
        mkdir $aa/$bb
        dd if=/dev/zero of=$aa/$bb/file$aa$bb.txt count=$count bs=$size
        foreach cc ( $level3 ) 
            mkdir $aa/$bb/$cc
            dd if=/dev/zero of=$aa/$bb/$cc/file$aa$bb$cc.txt count=$count bs=$size
        end
    end
end
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 May 2015 15:32:21 GMT</pubDate>
    <dc:creator>DolphinA2</dc:creator>
    <dc:date>2015-05-21T15:32:21Z</dc:date>
    <item>
      <title>Dropbox Java API - java.net.SocketException: Too many open files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58280#M1843</link>
      <description>&lt;P&gt;I am using Dropbox Java API to make a large amount of requests to Dropbox API to createFolder and upload files.  Currently, I am doing this sequentially, that is, no parallel thread, etc.   I am regularly getting the above error from Dropbox.   The pseudo code basically looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DbxRequestConfig config = new DbxRequestConfig(CLIENT_IDENTIFIER, Locale.getDefault().toString());

DbxClient client = new DbxClient(requestConfig, accessToken);

for ( int di = ; di &amp;lt; (large number) ; ++di ) 
    DbxEntry.Folder folderEntry = client.createFolder(somePath[di]);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;client.createFolder&lt;/CODE&gt; will throw &lt;CODE&gt;DbxException&lt;/CODE&gt;, specifically on &lt;CODE&gt;DbxException.NetworkIO&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Does the API close all the socket properly after each request?&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:42:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58280#M1843</guid>
      <dc:creator>DolphinA2</dc:creator>
      <dc:date>2019-05-29T09:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox Java API - java.net.SocketException: Too many open files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58281#M1844</link>
      <description>&lt;P&gt;Thanks for the report. For reference, can you let us know about how many requests you make before this happens, and post the full output for the exception? Thanks in advance! &lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2015 04:21:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58281#M1844</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2015-05-21T04:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox Java API - java.net.SocketException: Too many open files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58282#M1845</link>
      <description>&lt;P&gt;Below is the script we used to create a directory structure for testing.   Because Dropbox does not have any API for bulk upload, we essentially traverse the directory tree, and upload file and create directories one at a time.   The program would throw "java.net.SocketException:  Too many open files"  error.  I would say, around 20+ directory creation.  I checked out your Java API source code, my guess is that there are a few places in your DBRequestUtil.java that DropboxAPI team hasn't closed the &lt;CODE&gt;InputStream&lt;/CODE&gt; properly.  One of the example is &lt;CODE&gt;readJsonFromResponse()&lt;/CODE&gt; function call, the result is simple returned with 'return reader.readFully(body)'.  I have changed it to the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;T t = reader.readFully(body);
if ( body != null )  body.close();
return t;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;______ script for creating directories for testing ________&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/local/bin//tcsh -f
set level1 = ( a b c d e f g h i j )
set level2 = ( 1 2 3 4 5 6 7 8 9 0 )
set level3 = ( p q r s t u v w x y )
set size = 1024
set count = 128

foreach aa ( $level1 ) 
    mkdir $aa
    dd if=/dev/random of=$aa/file$aa.txt count=$count bs=$size
    foreach bb ( $level2 )
        mkdir $aa/$bb
        dd if=/dev/zero of=$aa/$bb/file$aa$bb.txt count=$count bs=$size
        foreach cc ( $level3 ) 
            mkdir $aa/$bb/$cc
            dd if=/dev/zero of=$aa/$bb/$cc/file$aa$bb$cc.txt count=$count bs=$size
        end
    end
end
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 May 2015 15:32:21 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58282#M1845</guid>
      <dc:creator>DolphinA2</dc:creator>
      <dc:date>2015-05-21T15:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox Java API - java.net.SocketException: Too many open files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58283#M1846</link>
      <description>&lt;P&gt;We currently aren't able to reproduce the issue ourselves.  Do you get the error when you only call &lt;CODE&gt;createFolder&lt;/CODE&gt; in a loop?  Or do you also have to call &lt;CODE&gt;uploadFile&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;readJsonFromResponse()&lt;/CODE&gt; function is not responsible for closing the stream.  There's higher-level code that should close the stream.&lt;/P&gt;

&lt;P&gt;I found an open source "file leak detector" (&lt;A href="http://file-leak-detector.kohsuke.org/" rel="nofollow noreferrer"&gt;http://file-leak-detector.kohsuke.org/&lt;/A&gt;).  I've never used it before, but it looks straightforward.  That might help locate the issue.&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2015 04:00:26 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58283#M1846</guid>
      <dc:creator>Kannan G.1</dc:creator>
      <dc:date>2015-05-22T04:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox Java API - java.net.SocketException: Too many open files</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58284#M1847</link>
      <description>&lt;P&gt;The loop has both createFolder() and uploadFile().  It does not happen all the time, and it happens randomly in the same loop.  But when it happens, it seems to be on the createFolder() only, and I haven't gotten it on uploadFile() call.&lt;/P&gt;

&lt;P&gt;Let me dig into your suggested library below and see if I have a better understanding on what causes the java.net.SocketException and get back to you.&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2015 07:19:53 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Java-API-java-net-SocketException-Too-many-open-files/m-p/58284#M1847</guid>
      <dc:creator>DolphinA2</dc:creator>
      <dc:date>2015-05-22T07:19:53Z</dc:date>
    </item>
  </channel>
</rss>

