Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-3216

PooledInvokerProxy.getPooledConnection() is not threadsafe

XMLWordPrintable

    • Low

      Code from 4.0.3SP1
      =================
      protected ClientSocket getPooledConnection()
      {
      ClientSocket socket = null;
      while (pool.size() > 0)
      {
      socket = (ClientSocket)pool.removeFirst();
      try

      { // Test to see if socket is alive by send ACK message final byte ACK = 1; socket.out.writeByte(ACK); socket.out.flush(); socket.in.readByte(); return socket; }
      catch (Exception ex)
      {
      try
      { socket.socket.close(); }
      catch (Exception ignored) {}
      }
      }
      return null;
      }
      ===========================
      Should be changed to:

      protected ClientSocket getPooledConnection()
      {
      ClientSocket socket = null;
      synchronized (pool) {
      while (pool.size() > 0)
      {
      socket = (ClientSocket)pool.removeFirst();
      try
      { // Test to see if socket is alive by send ACK message final byte ACK = 1; socket.out.writeByte(ACK); socket.out.flush(); socket.in.readByte(); return socket; }

      catch (Exception ex)
      {
      try

      { socket.socket.close(); }
      catch (Exception ignored) {}
      }
      }
      }
      return null;
      }

      ===========================
      ....or perhaps better:

      protected ClientSocket getPooledConnection()
      {
      ClientSocket socket = null;
      while (pool.size() > 0)
      {
      try { socket = (ClientSocket)pool.removeFirst(); }
      catch (java.util.NoSuchElementException nsee)
      { return null; }

      try
      { // Test to see if socket is alive by send ACK message final byte ACK = 1; socket.out.writeByte(ACK); socket.out.flush(); socket.in.readByte(); return socket; }
      catch (Exception ex)
      {
      try
      { socket.socket.close(); }

      catch (Exception ignored) {}
      }
      }
      return null;
      }

            starksm64 Scott Stark (Inactive)
            anders-l.welen@polisen.se Anders Welen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: