-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-3980: Fix DefaultSftpSFactory for concurrency #3981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright 2002-2022 the original author or authors. | ||
| * Copyright 2002-2023 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. | ||
|
|
@@ -320,7 +320,7 @@ private ClientSession initClientSession() throws IOException { | |
| return clientSession; | ||
| } | ||
|
|
||
| private void initClient() throws IOException { | ||
| private synchronized void initClient() throws IOException { | ||
| if (this.initialized.compareAndSet(false, true)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, we can use volatile boolean instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... Makes sense. |
||
| if (this.port <= 0) { | ||
| this.port = SshConstants.DEFAULT_PORT; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synchronization has to be higher up - otherwise if
isSharedSessionis true, we could orphan a session; see code ingetSession.spring-integration/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java
Lines 286 to 288 in f8fff81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
isSharedSessionwe dothis.sharedSessionLock.lock();There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops - right; ignore.