Skip to content
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

[LIVY-1001][RSC] ContextLauncher has a potential NullPointerException… #447

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions rsc/src/main/java/org/apache/livy/rsc/RSCClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.livy.LivyClient;
import org.apache.livy.LivyClientFactory;
import org.apache.livy.rsc.rpc.RpcServer;
Expand All @@ -33,6 +36,7 @@
* Factory for RSC clients.
*/
public final class RSCClientFactory implements LivyClientFactory {
private static final Logger LOG = LoggerFactory.getLogger(RSCClientFactory.class);

private final AtomicInteger refCount = new AtomicInteger();
private RpcServer server = null;
Expand Down Expand Up @@ -87,27 +91,36 @@ RpcServer getServer() {
}

private synchronized void ref(RSCConf config) throws IOException {
if (refCount.get() != 0) {
if (refCount.get() > 0) {
refCount.incrementAndGet();
return;
}

Utils.checkState(server == null, "Server already running but ref count is 0.");
Utils.checkState(server == null,
String.format("Server already running but ref count is %s.", refCount.get()));
if (server == null) {
try {
server = new RpcServer(config);
refCount.incrementAndGet();
} catch (InterruptedException ie) {
throw Utils.propagate(ie);
}
}

refCount.incrementAndGet();
}

synchronized void unref() {
if (refCount.decrementAndGet() == 0) {
server.close();
server = null;
if (refCount.decrementAndGet() <= 0) {
LOG.info("Un reference rpc server {} refCount {}", server, refCount.get());
try {
if (server != null) {
server.close();
}
} catch (Exception e) {
LOG.error("Un reference rpc server exception", e);
} finally {
server = null;
refCount.set(0);
}
}
}

Expand Down