This is an automated email from the ASF dual-hosted git repository.
lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
The following commit(s) were added to refs/heads/master by this push:
new a860fdb [SSHD-916] Avoid locking the session lock when signalling
client session authentication failure
a860fdb is described below
commit a860fdb37955f294b63e98bf16314e177e0ed217
Author: Lyor Goldstein <[email protected]>
AuthorDate: Tue May 14 07:50:18 2019 +0300
[SSHD-916] Avoid locking the session lock when signalling client session
authentication failure
---
CHANGES.md | 2 ++
.../sshd/client/session/ClientSessionImpl.java | 21 +++++++++++++++------
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 4065378..2011c87 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -133,4 +133,6 @@ and therefore closing all currently tracked file/directory
handles.
* [SSHD-912](https://issues.apache.org/jira/browse/SSHD-912) - Use separate
locks for Future(s) and Session/Channel instances.
+* [SSHD-916](https://issues.apache.org/jira/browse/SSHD-916) - Avoid locking
the session lock when signalling client session authentication failure.
+
* [SSHD-917](https://issues.apache.org/jira/browse/SSHD-917) - Add support for
SSH2 public key file format.
diff --git
a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
index 73558ac..200e3c3 100644
---
a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
+++
b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
@@ -148,16 +148,25 @@ public class ClientSessionImpl extends
AbstractClientSession {
protected void signalAuthFailure(AuthFuture future, Throwable t) {
boolean signalled = false;
- synchronized (sessionLock) {
- if ((future != null) && (!future.isDone())) {
- future.setException(t);
- signalled = true;
+ if (future != null) {
+ /*
+ * SSHD-916 - do not synchronize on the session lock since the
+ * result of setting an exception may be an exchange of messages
+ * due to one of the registered listeners. If this is the case
+ * then a deadlock will occur since the session's message handling
+ * loop also tries to lock the session lock - but on another
thread.
+ */
+ synchronized (future) {
+ if (!future.isDone()) {
+ future.setException(t);
+ signalled = true;
+ }
}
}
if (log.isDebugEnabled()) {
- log.debug("signalAuthFailure({}) type={}, signalled={},
message=\"{}\"",
- this, t.getClass().getSimpleName(), signalled,
t.getMessage());
+ log.debug("signalAuthFailure({}) type={}, signalled={}: {}",
+ this, t.getClass().getSimpleName(), signalled, t.getMessage());
}
}