BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-23-2004, 06:41 PM   #1
pogi
Knows Where the Search Button Is
 
Join Date: Sep 2004
Posts: 15
Default java.io.IOException: Max connections opened

Please Login to Remove!

My application opens a bunch of http connections (once at a time..after its finished it closes the inputstream and connection), but after about 20 opening/closing connections it throws this IOException. I'm using the same inputstream object and streamconnection object each time i'm connecting to the server. any ideas on why this is happening?
Offline  
Old 09-23-2004, 07:33 PM   #2
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

1. Use a seperate thread for the http openning/closing.

2. Add a sleep after closing and opening.
Offline  
Old 09-23-2004, 07:57 PM   #3
pogi
Knows Where the Search Button Is
 
Join Date: Sep 2004
Posts: 15
Default

It uses a thread to open/close. How long of a sleep should I put when I open/close?
Offline  
Old 09-23-2004, 08:35 PM   #4
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

Do some experimentation...start with about 10 ms.
Offline  
Old 09-24-2004, 01:53 PM   #5
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

Actually I was doing some testing, and it looks like a lot of http connections hang after you close them ( i.e. you can't reopen the same one).
Offline  
Old 09-25-2004, 11:48 PM   #6
pogi
Knows Where the Search Button Is
 
Join Date: Sep 2004
Posts: 15
Default

So.. its impossible to close them? How does programs like ReqWireless open/close so many http connections without blowing up?
Offline  
Old 09-27-2004, 02:27 PM   #7
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

What version of BlackberryOS are you using? Some of the more stable versions are the later versions of 3.7.1.XXX (i.e. 3.7.1.92)
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 09-30-2004, 02:39 PM   #8
pogi
Knows Where the Search Button Is
 
Join Date: Sep 2004
Posts: 15
Default

I'm using 3.7.2.15 on a Nextel 7510. It crashes on both the simulator and actual device.
Offline  
Old 10-01-2004, 02:23 PM   #9
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

Hmm, probably an OS limitation. Try these:

1. Reuse the same object for multiple HTTP connections one after another.

2. Create, use one HTTP connection then destroy. Never reuse the same HTTP connection object twice after closing it.

One of the two approaches will probably solve your problem. Try both!
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 10-02-2004, 02:47 PM   #10
pogi
Knows Where the Search Button Is
 
Join Date: Sep 2004
Posts: 15
Default

lol. I've tried #1. I'll try #2 and post how it goes.
Offline  
Old 01-29-2007, 10:47 AM   #11
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default Was this problem solved?

I'm having this exact problem. Has anyone had any luck solving it?

I'm calling close() on my connection object, which after being initiated about 20 different times gives me an IOException, Max Connections Open.

Anybody know how I can get around this problem?

Cheers, Ben
Offline  
Old 02-05-2007, 04:02 AM   #12
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default

I managed to solve this problem by creating a ConnectionManager class that looks after a single static connection, and then share the ConnectionManager.

After doing some more reading around it seems that the Connection.close() issue (ie. the connections not always closing properly and causing a Max Connections Opened error) is a BlackBerry OS bug. Does anyone know if this is officially documented anywhere?
Offline  
Old 02-13-2007, 10:54 AM   #13
dane
New Member
 
Join Date: Feb 2007
Model: 7290
Carrier: TMobile
Posts: 4
Default

The problem is probably caused because of improper closing of connections.

The maximum number of connections that the device can open when there is no MDS present is 5. If the connections are improperly closed, that limit can be reached quite soon and you will have to wait for the connections to timeout.

Search for max connections in the blackberry knowledge base (i'm not yet allowed to post links)

The trick is wrapping the closing of input stream, output stream and connection each in its own try..catch block, otherwise an exception might be thrown in one of them and the other two might not be processed thus not closing the connection properly.
Offline  
Old 02-22-2007, 02:21 PM   #14
egalexe
Knows Where the Search Button Is
 
Join Date: Feb 2007
Model: 9000
Carrier: SFR
Posts: 48
Default

Hi I had the same kind of troubles.
What I did:
=> You should close connection but streams too, so be sur too close everything properly.
=> The sleep is a very good idea. There is a small delays when you close the socket before it "really" close it.
=> If you are using the default exit menu as it is, that will leave the application without closing sockets & streams!!! Idem if you get phone call or put the application in background.
Offline  
Old 09-13-2007, 06:19 PM   #15
leisti
New Member
 
Join Date: Jul 2007
Model: 8707v
PIN: N/A
Carrier: Vodafone
Posts: 1
Default also experiencing this problem; can't find solution

I'm experiencing the same problem. I've opened an HTTP socket to a web server, and then opened the input stream and output stream from the socket. Using the sockets from my app works fine both in the simulator and in a real device (tested on 8707v and 8100), and closing the socket works fine on the simulator.

However, when using the app in a real device, over BES, something goes wrong when the app attempts to close the sockets. It seems that the final handshake of the three-handshake TCP socket-closing procedure is not sent from the device to the web server, perhaps being somehow eaten by BES. This leaves the socket hanging in the server, which keeps it open until the app closes (because this is the way we've programmed the web server to work).

As our app closes an old socket and opens a new one as the user moves from screen to screen, the problem leads, in the worst case, to the app having lots of open sockets, using up the resources, and possibly freezing the app.

We've added the code suggested in this thread to closing the socket: we're closing both the input and output streams before closing the socket; we're sleeping for a bit after each call of close; and we're enclosing the closes inside a try-block. Even lengthening the sleep time to one second did not affect the problem.

Below, the code that opens the sockets and the code that closes them. Note that at the end of the method CloseSocket, the closes never throw an exception, and at the end, the code always reports that three closes were successful. However, the sockets still hang there.

Any ideas, anybody???

Code:
    /**
     * Send the initial request.
     */
    public synchronized void SendRequest() throws IOException, OwnException
        {
        // returns
        // "socket://<ip_address>:<port>;deviceside=true;apn=internet"
        // where <ip_address> is the configured IP address and <port>
        // is the configured port:
        String service = monitor_.GetConnectionService();

        SocketConnection socket = ( SocketConnection )Connector.open( service );

        socket.setSocketOption( SocketConnection.DELAY, 0 );

        if ( socket != null )
            {
            socket_in_ = socket.openDataInputStream();
            socket_out_ = socket.openDataOutputStream();

            if ( socket_ == null )
                {
                socket_ = socket;
                }
            else
                {
                throw new OwnException( "unclosed socket!" );
                }

            SendRequest( message_, socket_out_ );
            }
        else
            {
            // No socket is available, most likely mobile data is
            // down.  Error ourselves.
            ChangeState( state_.ErrorOrOtherFinalEvent( this ) );
            }
        }



    /**
     * @param socket SocketConnection to close.
     * @param socket_in DataInputStream to close.
     * @param socket_out DataOutputStream to close.
     */
    private static void CloseSocket( SocketConnection socket,
                                     DataInputStream  socket_in,
                                     DataOutputStream socket_out )
        {
        int connections_closed = 0;

        try
            {
            if ( socket_in != null )
                {
                // log this
                ++ connections_closed;
                socket_in.close();
                Thread.sleep( GlobalConstants.SLEEP_AFTER_CLOSING_SOCKET );
                }
            }
        catch ( IOException ex )
            {
            -- connections_closed;
            // log this
            }
        catch ( InterruptedException ex )
            {
            -- connections_closed;
            // log this
            }
        finally
            {
            socket_in = null;
            }

        try
            {
            if ( socket_out != null )
                {
                // log this
                ++ connections_closed;
                socket_out.close();
                Thread.sleep( GlobalConstants.SLEEP_AFTER_CLOSING_SOCKET );
                }
            }
        catch ( IOException ex )
            {
            -- connections_closed;
            // log this
            }
        catch ( InterruptedException ex )
            {
            -- connections_closed;
            // log this
            }
        finally
            {
            socket_out = null;
            }

        try
            {
            if ( socket != null )
                {
                // log this
                ++ connections_closed;
                socket.close();
                Thread.sleep( GlobalConstants.SLEEP_AFTER_CLOSING_SOCKET );
                }
            }
        catch ( IOException ex )
            {
            -- connections_closed;
            // log this
            }
        catch ( InterruptedException ex )
            {
            -- connections_closed;
            // log this
            }
        finally
            {
            socket = null;
            }

        // log connections_closed
        }

Last edited by leisti; 09-13-2007 at 06:24 PM.. Reason: giving more information
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


CBB60 Motor Run Capacitor 450VAC 10uF/20uF/30uF/40uF/50uF 4 Pins CE Standard picture

CBB60 Motor Run Capacitor 450VAC 10uF/20uF/30uF/40uF/50uF 4 Pins CE Standard

$12.99



ABB Capacitor Unit 3HAC14551-3/05A picture

ABB Capacitor Unit 3HAC14551-3/05A

$949.95



CBB65A Round Electric Motor Start Run Capacitor 450VAC 50uf 50MFD Aluminum picture

CBB65A Round Electric Motor Start Run Capacitor 450VAC 50uf 50MFD Aluminum

$9.53



Nichicon Capacitor CE 85C NX 450V 8200uF  picture

Nichicon Capacitor CE 85C NX 450V 8200uF

$67.45



6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF picture

6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF

$155.59



CBB61 250V  Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF picture

CBB61 250V Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF

$129.95







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.