From 43cb48443ff1a3d5d8cba80a0bfd29568160bf3e Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 26 Aug 2021 11:47:13 -0400 Subject: [PATCH] GH-3620: Fix Shared SFTP Session Resolves https://github.com/spring-projects/spring-integration/issues/3620 Shared session field was captured outside of the lock, causing multiple sessions in a multi-threaded environment. **cherry-pick to 5.4.x, 5.3.x** --- .../integration/sftp/session/DefaultSftpSessionFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java index bc361f38b6..a6e1a056ba 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -382,11 +382,11 @@ public class DefaultSftpSessionFactory implements SessionFactory, Share @Override public SftpSession getSession() { - JSchSessionWrapper jschSession = this.sharedJschSession; SftpSession sftpSession; if (this.sharedSessionLock != null) { this.sharedSessionLock.lock(); } + JSchSessionWrapper jschSession = this.sharedJschSession; try { boolean freshJschSession = false; if (jschSession == null || !jschSession.isConnected()) {