Announcement Announcement Module
Collapse
No announcement yet.
java.net.BindException: Address already in use: connect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.net.BindException: Address already in use: connect

    I have a spring app running from eclipse. I have two computers running the same app. With one I get the above exception. The other runs fine.

    The app hits a Mysql db with a lot of updates. The break occurs at diffferent places in my code depending on what updates I run.

    The computer that works is running windows 2000. The one that breaks is running XP pro. Other than that the configurations are as identical as I can make them.

    Thanks in advance for any help

    Hal Haig
    617 624-0440

  • #2
    In what context does the error appear? Can you post a stack trace and your configuration?

    Rob

    Comment


    • #3
      stack trace and configuration info

      Im using mysql-connector-java-3.0.15-ga-bin
      with MySql Server 4.1.

      Below is the stack trace:

      what other info would be helpful?


      org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not get JDBC connection; nested exception is java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.BindException: Address already in use: connect

      ** BEGIN NESTED EXCEPTION **

      java.net.BindException
      MESSAGE: Address already in use: connect

      STACKTRACE:

      java.net.BindException: Address already in use: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:305)
      at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:171)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:158)
      at java.net.Socket.connect(Socket.java:452)
      at java.net.Socket.connect(Socket.java:402)
      at java.net.Socket.<init>(Socket.java:309)
      at java.net.Socket.<init>(Socket.java:124)
      at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:124)
      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
      at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1779)
      at com.mysql.jdbc.Connection.<init>(Connection.java:4 50)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:411)
      at java.sql.DriverManager.getConnection(DriverManager .java:512)
      at java.sql.DriverManager.getConnection(DriverManager .java:171)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:156)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:144)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnection(DriverManagerDataSource.ja va:132)
      at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:173)
      at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:152)
      at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:128)
      at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:319)
      at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:522)
      at org.springframework.jdbc.object.SqlUpdate.update(S qlUpdate.java:166)
      at db.TableImpl$InsertAndGenerateKey.run(TableImpl.ja va:140)
      at db.TableImpl.add(TableImpl.java:240)
      at util.ListStoreImpl$Cache.close(ListStoreImpl.java: 54)
      at util.ListStoreImpl$Cache.open(ListStoreImpl.java:1 05)
      at util.ListStoreImpl$Cache.openSegmentForWrite(ListS toreImpl.java:116)
      at util.ListStoreImpl$Cache.access$1500(ListStoreImpl .java:27)
      at util.ListStoreImpl.getSegmentForWrite(ListStoreImp l.java:814)
      at util.ListStoreImpl.setFloat(ListStoreImpl.java:877 )
      at util.Series.f(Series.java:77)
      at calc.Stocks.dailyReturnWoDiv(Stocks.java:235)
      at calc.Stocks.setSeries(Stocks.java:144)
      at calc.Stocks.setSeries(Stocks.java:132)
      at web.Main.store(Main.java:40)
      at web.Main.recreateDb(Main.java:54)
      at web.Main.main(Main.java:62)


      ** END NESTED EXCEPTION **


      java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.BindException: Address already in use: connect

      ** BEGIN NESTED EXCEPTION **

      java.net.BindException
      MESSAGE: Address already in use: connect

      STACKTRACE:

      java.net.BindException: Address already in use: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:305)
      at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:171)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:158)
      at java.net.Socket.connect(Socket.java:452)
      at java.net.Socket.connect(Socket.java:402)
      at java.net.Socket.<init>(Socket.java:309)
      at java.net.Socket.<init>(Socket.java:124)
      at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:124)
      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
      at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1779)
      at com.mysql.jdbc.Connection.<init>(Connection.java:4 50)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:411)
      at java.sql.DriverManager.getConnection(DriverManager .java:512)
      at java.sql.DriverManager.getConnection(DriverManager .java:171)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:156)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:144)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnection(DriverManagerDataSource.ja va:132)
      at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:173)
      at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:152)
      at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:128)
      at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:319)
      at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:522)
      at org.springframework.jdbc.object.SqlUpdate.update(S qlUpdate.java:166)
      at db.TableImpl$InsertAndGenerateKey.run(TableImpl.ja va:140)
      at db.TableImpl.add(TableImpl.java:240)
      at util.ListStoreImpl$Cache.close(ListStoreImpl.java: 54)
      at util.ListStoreImpl$Cache.open(ListStoreImpl.java:1 05)
      at util.ListStoreImpl$Cache.openSegmentForWrite(ListS toreImpl.java:116)
      at util.ListStoreImpl$Cache.access$1500(ListStoreImpl .java:27)
      at util.ListStoreImpl.getSegmentForWrite(ListStoreImp l.java:814)
      at util.ListStoreImpl.setFloat(ListStoreImpl.java:877 )
      at util.Series.f(Series.java:77)
      at calc.Stocks.dailyReturnWoDiv(Stocks.java:235)
      at calc.Stocks.setSeries(Stocks.java:144)
      at calc.Stocks.setSeries(Stocks.java:132)
      at web.Main.store(Main.java:40)
      at web.Main.recreateDb(Main.java:54)
      at web.Main.main(Main.java:62)


      ** END NESTED EXCEPTION **


      at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1847)
      at com.mysql.jdbc.Connection.<init>(Connection.java:4 50)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:411)
      at java.sql.DriverManager.getConnection(DriverManager .java:512)
      at java.sql.DriverManager.getConnection(DriverManager .java:171)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:156)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:144)
      at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnection(DriverManagerDataSource.ja va:132)
      at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:173)
      at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:152)
      at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:128)
      at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:319)
      at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:522)
      at org.springframework.jdbc.object.SqlUpdate.update(S qlUpdate.java:166)
      at db.TableImpl$InsertAndGenerateKey.run(TableImpl.ja va:140)
      at db.TableImpl.add(TableImpl.java:240)
      at util.ListStoreImpl$Cache.close(ListStoreImpl.java: 54)
      at util.ListStoreImpl$Cache.open(ListStoreImpl.java:1 05)
      at util.ListStoreImpl$Cache.openSegmentForWrite(ListS toreImpl.java:116)
      at util.ListStoreImpl$Cache.access$1500(ListStoreImpl .java:27)
      at util.ListStoreImpl.getSegmentForWrite(ListStoreImp l.java:814)
      at util.ListStoreImpl.setFloat(ListStoreImpl.java:877 )
      at util.Series.f(Series.java:77)
      at calc.Stocks.dailyReturnWoDiv(Stocks.java:235)
      at calc.Stocks.setSeries(Stocks.java:144)
      at calc.Stocks.setSeries(Stocks.java:132)
      at web.Main.store(Main.java:40)
      at web.Main.recreateDb(Main.java:54)
      at web.Main.main(Main.java:62)
      Exception in thread "main"

      Comment


      • #4
        is NonRegisteringDriver the root cause?

        i noticed:

        com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:411)

        in the first stack trace. What would cause that and is that the root cause?

        Comment


        • #5
          it was XP

          I switched the OS to Windows 2000 from Windows XP Pro, and everything worked again.

          Comment


          • #6
            Are you sure you installed the proper mysql driver on the XP computer? You also need to make sure that you include THAT driver in your XP app's library.

            Take care,
            James

            Comment


            • #7
              This looks like something is already listening on the port for MySql in XP, but not in Windows 2000. Did you try to list all ports before you start your application with
              Code:
              netstat -a
              ?

              Comment


              • #8
                I installed mysql using the standard setup program. I would assume (perhaps incorrectly) that it would properly install the drivers. I did use the same JDBC driver for both XP and 2000. (I even tried updating to latest JDBC driver).

                I may have not been totally clear. While running under XP my app did perform many successfully db operations. But after a few thousand or so updates and reads in a tight loop, it would eventually crash. A sample trace is included in a prior posting.

                I did not list all the ports using the "netstat -a". Perhaps I had my ports mis-configured.

                At this point, I running 2000 without problems and on to new challenges.

                Thanks for the help

                Comment


                • #9
                  This sounds like a problem with MySQL rather than Spring. I think that you may have to configure auto reconnect for your connection although I am not entirely sure about that. You shoul probably post into MySQL forums since they are much more likely to have seen this problem before.

                  Regards,

                  Rob

                  Comment


                  • #10
                    use commons dbcp instead

                    As per the documentation for org.springframework.jdbc.datasource.DriverManagerD ataSource, I changed my DataSource bean to use the org.apache.commons.dbcp.BasicDataSource instead, and this problem went away for me.

                    Jon Moore
                    Comcast Interactive Media

                    Comment


                    • #11
                      I Found Reason

                      Please visit this site http://bugs.mysql.com/bug.php?id=16161.

                      "This only happens if the application opens more database connections than your
                      operating system will support on the _client_ side. There are a fixed number of
                      outbound ports that can be used for establishing TCP/IP connections, and they
                      are only available for re-use after some timeout period (typically 15 minutes)
                      after they've been closed"

                      MAY BE THIS CAN HELP OTHERS

                      Comment


                      • #12
                        Strictly speaking - that's not true. If every application would be somehow bound by the number of sockets it can open and close in a short period of time we would all be aware of it as that would mean tcp/ip a toy and not a protocol the world revolves around. Actually, it's just mysql driver that's not using Socket.setReuseAddress() as it should.

                        Comment

                        Working...
                        X