Skip to content

Commit 3e3e180

Browse files
committed
Improve FTPS server shutdown to prevent port conflicts
Added more robust shutdown logic in AbstractFtpsProviderTestCase.tearDownClass(): - Wait 300ms after suspend() to allow active connections to finish - Increased retry count from 10 to 20 for server stop wait - Clear all static fields (socketPort, connectionUri) after shutdown - Increased final wait from 500ms to 1000ms to ensure port is fully released This helps prevent issues when running multiple FTPS test classes sequentially in the same JVM, though the tests still work best when run in separate forks.
1 parent 741eec7 commit 3e3e180

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,22 @@ synchronized static void setUpClass(final boolean implicit) throws FtpException
154154
*/
155155
synchronized static void tearDownClass() {
156156
if (embeddedFtpServer != null) {
157+
// First suspend to stop accepting new connections
157158
embeddedFtpServer.suspend();
159+
160+
// Wait a bit for active connections to finish
161+
try {
162+
Thread.sleep(300);
163+
} catch (final InterruptedException e) {
164+
e.printStackTrace();
165+
}
166+
167+
// Now stop the server
158168
embeddedFtpServer.stop();
159169
Thread.yield();
160-
int count = 10;
170+
171+
// Wait for server to fully stop
172+
int count = 20; // Increased from 10 to 20
161173
while (count-- > 0 && !embeddedFtpServer.isStopped()) {
162174
final int millis = 200;
163175
System.out.println(String.format("Waiting %,d milliseconds for %s to stop", millis, embeddedFtpServer));
@@ -167,7 +179,18 @@ synchronized static void tearDownClass() {
167179
e.printStackTrace();
168180
}
169181
}
182+
183+
// Clear the reference
170184
embeddedFtpServer = null;
185+
socketPort = 0;
186+
connectionUri = null;
187+
188+
// Additional wait to ensure port is fully released and all resources cleaned up
189+
try {
190+
Thread.sleep(1000); // Increased from 500 to 1000
191+
} catch (final InterruptedException e) {
192+
e.printStackTrace();
193+
}
171194
}
172195
}
173196

0 commit comments

Comments
 (0)