Skip to content

FtpRemoteFileTemplate connection leak with ExistsMode.NLST_AND_DIRS #2820

Closed
@zyro23

Description

@zyro23

Affects Version(s): spring-integration-ftp-5.1.3.RELEASE


Bug report

FtpRemoteFileTemplate#exists seems to open connections that are not closed by the surrounding callback handlers with ExistsMode.NLST_AND_DIRS:
https://github.com/spring-projects/spring-integration/blob/v5.1.3.RELEASE/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpRemoteFileTemplate.java#L95

i was not really sure how to assert that all connections are closed properly in a short test, but if you put the snippet below into FtpRemoteFileTemplateTests (https://github.com/spring-projects/spring-integration/blob/v5.1.3.RELEASE/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/session/FtpRemoteFileTemplateTests.java#L126) and debug into AbstractFtpSessionFactory#createClient/FtpSession#close, you can see that 3 connections are opened but only 2 are closed.

@Test
public void testConnectionClosedAfterExists() throws Exception {
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory);
    template.setRemoteDirectoryExpression(new LiteralExpression("/"));
    template.setExistsMode(FtpRemoteFileTemplate.ExistsMode.NLST_AND_DIRS);
    template.afterPropertiesSet();
    File file = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    fileOutputStream.write("foo".getBytes());
    fileOutputStream.close();
    template.send(new GenericMessage<>(file), FileExistsMode.IGNORE);
    File newFile = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    assertThat(file.renameTo(newFile)).isTrue();
    file.delete();
    newFile.delete();
}

as that test case by itself is passing and somewhat incomplete (problem can only be observed debugging into the code..), i was a bit reluctant to put together a sample project.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions