summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColby Ranger <cranger@google.com>2012-04-25 14:35:18 -0700
committerSasa Zivkov <sasa.zivkov@sap.com>2012-05-31 17:27:39 +0200
commit4d741c29e5e1446091c57937edb89a6faf2aabb7 (patch)
tree4d76d6ac9708df96c4f4a3ec91d64ca7994fc0f2
parent63a0fcc4925c43aeac3b8c16f6b4f675e3eda34a (diff)
Fixed cleanup of propagated SshScopes
The RequestScopePropagator handles RequestCleanup independently of the original context. However, SshScope.Context.subContext() was chaining the cleanup in the parent. This would cause an exception if the parent scope happened to finish before the sub-context. Since cleanup is already handled correctly by the RequestScopePropagator, don't register the continued contect with the original context cleanup. Change-Id: Ie508d1921050887b95dd18bc5806c17e4894391f
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java28
1 files changed, 12 insertions, 16 deletions
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java
index f923d80fb0..92609b5235 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java
@@ -39,7 +39,7 @@ class SshScope {
volatile long started;
volatile long finished;
- Context(final SshSession s, final String c) {
+ private Context(final SshSession s, final String c, final long at) {
cleanup = new RequestCleanup();
session = s;
commandLine = c;
@@ -47,25 +47,17 @@ class SshScope {
map = new HashMap<Key<?>, Object>();
map.put(RC_KEY, cleanup);
- final long now = System.currentTimeMillis();
- created = now;
- started = now;
- finished = now;
+ created = started = finished = at;
}
private Context(Context p, SshSession s, String c) {
- cleanup = new RequestCleanup();
- session = s;
- commandLine = c;
-
- map = new HashMap<Key<?>, Object>();
- map.put(RC_KEY, cleanup);
-
- created = p.created;
+ this(s, c, p.created);
started = p.started;
finished = p.finished;
+ }
- p.cleanup.add(cleanup);
+ Context(final SshSession s, final String c) {
+ this(s, c, System.currentTimeMillis());
}
String getCommandLine() {
@@ -87,7 +79,9 @@ class SshScope {
}
synchronized Context subContext(SshSession newSession, String newCommandLine) {
- return new Context(this, newSession, newCommandLine);
+ Context ctx = new Context(this, newSession, newCommandLine);
+ cleanup.add(ctx.cleanup);
+ return ctx;
}
}
@@ -112,7 +106,9 @@ class SshScope {
@Override
protected Context continuingContext(Context ctx) {
- return ctx.subContext(ctx.getSession(), ctx.getCommandLine());
+ // The cleanup is not chained, since the RequestScopePropagator executors
+ // the Context's cleanup when finished executing.
+ return new Context(ctx, ctx.getSession(), ctx.getCommandLine());
}
}