From a1440621f967d1bf1bf3af002d0d9b5f0c8c8706 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 20 Dec 2013 15:06:56 -0500 Subject: [PATCH] Fix a race that could crash a few threads in the input thread pool --- .../src/com/limelight/nvstream/NvConnection.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/NvConnection.java b/moonlight-common/src/com/limelight/nvstream/NvConnection.java index edbe0598..345c1d7d 100644 --- a/moonlight-common/src/com/limelight/nvstream/NvConnection.java +++ b/moonlight-common/src/com/limelight/nvstream/NvConnection.java @@ -194,8 +194,13 @@ public class NvConnection { private boolean startInputConnection() throws IOException { - inputStream = new NvController(hostAddr); - inputStream.initialize(); + // Because input events can be delivered at any time, we must only assign + // it to the instance variable once the object is properly initialized. + // This avoids the race where inputStream != null but inputStream.initialize() + // has not returned yet. + NvController tempController = new NvController(hostAddr); + tempController.initialize(); + inputStream = tempController; return true; }