davsclaus commented on code in PR #30596:
URL: https://github.com/apache/camel/pull/30596#discussion_r4657722556


##########
components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java:
##########
@@ -128,21 +144,66 @@ public boolean isConnected() throws 
GenericFileOperationFailedException {
     @Override
     public void disconnect() throws GenericFileOperationFailedException {
         loggedIn = false;
+        DiskShare currentShare = share;
+        Session currentSession = session;
+        Connection currentConnection = connection;
+        share = null;
+        session = null;
+        connection = null;
+        if (currentShare == null && currentSession == null && 
currentConnection == null) {
+            return;
+        }
+        if (endpoint == null) {
+            close(currentConnection, currentSession, currentShare);
+            return;
+        }
+        Thread disconnector = 
endpoint.getCamelContext().getExecutorServiceManager()
+                .newThread("SmbDisconnect", () -> close(currentConnection, 
currentSession, currentShare));
+        disconnector.start();
+        try {
+            disconnector.join(DISCONNECT_WAIT_MILLIS);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+        if (disconnector.isAlive()) {
+            LOG.warn("Disconnecting from {}:{} waits for the server, which 
does not answer."
+                     + " The disconnect completes in the background.",
+                    configuration.getHostname(), configuration.getPort());
+            // the SMB client hands out its open connection again to the next 
connect, until the connection is closed
+            if (smbClient != null) {
+                smbClient = createSmbClient();

Review Comment:
   Right, fixed in 5e71b3fc36c8. The old client is not closed right away: 
`SMBClient.close()` force-closes its connections, which would cut off the 
graceful close that is still running. Instead it is handed to the 
`SmbDisconnect` thread, which closes it after the share, the session and the 
connection (failures logged at DEBUG). If that thread completes between the 
timeout and the hand-over, `disconnect()` closes the client itself (an 
`AtomicBoolean` + `AtomicReference.getAndSet`, so it is closed exactly once). 
`SmbOperationsDisconnectTest.serverThatDoesNotAnswer` now checks the client is 
not closed while the server does not answer, and is closed after the connection 
once it does (it fails without the fix); 
`closesLeasedDirectoriesBeforeTheShare` checks a normal disconnect keeps the 
client.
   
   _Claude Code on behalf of davsclaus_



##########
components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java:
##########
@@ -128,21 +144,66 @@ public boolean isConnected() throws 
GenericFileOperationFailedException {
     @Override
     public void disconnect() throws GenericFileOperationFailedException {
         loggedIn = false;
+        DiskShare currentShare = share;
+        Session currentSession = session;
+        Connection currentConnection = connection;
+        share = null;
+        session = null;
+        connection = null;
+        if (currentShare == null && currentSession == null && 
currentConnection == null) {
+            return;
+        }
+        if (endpoint == null) {
+            close(currentConnection, currentSession, currentShare);
+            return;
+        }
+        Thread disconnector = 
endpoint.getCamelContext().getExecutorServiceManager()
+                .newThread("SmbDisconnect", () -> close(currentConnection, 
currentSession, currentShare));
+        disconnector.start();
+        try {
+            disconnector.join(DISCONNECT_WAIT_MILLIS);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+        if (disconnector.isAlive()) {
+            LOG.warn("Disconnecting from {}:{} waits for the server, which 
does not answer."
+                     + " The disconnect completes in the background.",
+                    configuration.getHostname(), configuration.getPort());
+            // the SMB client hands out its open connection again to the next 
connect, until the connection is closed
+            if (smbClient != null) {
+                smbClient = createSmbClient();
+            }
+        }
+    }
+
+    /**
+     * Closes the share, the session and the connection, in this order, 
ignoring failures.
+     */
+    static void close(Connection connection, Session session, DiskShare share) 
{

Review Comment:
   Fixed in 5e71b3fc36c8: the javadoc says `disconnect()` calls it from a 
background thread, as each close can wait for the server, and that it never 
throws: the failures are ignored so a server that went away cannot keep the 
session or the connection open.
   
   _Claude Code on behalf of davsclaus_



-- 
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