amichair commented on code in PR #58:
URL: https://github.com/apache/aries-rsa/pull/58#discussion_r3111265635


##########
provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpInvocationHandler.java:
##########
@@ -46,22 +49,105 @@
  * which sends the details of the method invocations
  * over a TCP connection, to be executed by the remote service.
  */
-public class TcpInvocationHandler implements InvocationHandler {
+public class TcpInvocationHandler implements InvocationHandler, Closeable {
+
+    private static class Connection {
+        Socket socket;
+        BasicObjectOutputStream out;
+        BasicObjectInputStream in;
+
+        public Connection(Socket socket) throws IOException {
+            this.socket = socket;
+            out = new BasicObjectOutputStream(socket.getOutputStream());
+            in = new BasicObjectInputStream(socket.getInputStream());
+        }
+    }
+
     private String host;
     private int port;
     private String endpointId;
     private ClassLoader cl;
     private int timeoutMillis;
 
+    private final Deque<Connection> pool = new ArrayDeque<>();
+    private int acquired; // counts connections currently in use (not in pool)
+    private boolean closed;
+
     public TcpInvocationHandler(ClassLoader cl, String host, int port, String 
endpointId, int timeoutMillis)
-        throws UnknownHostException, IOException {
+            throws UnknownHostException, IOException {
         this.cl = cl;
         this.host = host;
         this.port = port;
         this.endpointId = endpointId;
         this.timeoutMillis = timeoutMillis;
     }
 
+    private Connection acquireConnection() throws IOException {
+        Connection conn;
+        synchronized (pool) {
+            acquired++; // must be first

Review Comment:
   I'm not sure a limit is needed. This only protects the client from itself, 
and doesn't affect the server (a malicious client can just open its own 
sockets...). For a faulty client to open an exaggerated number of connections, 
it would first have to start an exaggerated number of threads to call the 
service concurrently, which means they will have bigger fish to fry in terms of 
resource use etc. The solution would be for the caller to manage its threads 
properly (and thus indirectly limit the number of connections) - I think that 
only limiting the number of connections would not achieve much.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to