diff options
author | Jiri Vanek <[email protected]> | 2013-05-20 15:13:32 +0200 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2013-05-20 15:13:32 +0200 |
commit | 0807c9fc6f5b44323c53413341eb4026de919ff6 (patch) | |
tree | dfa69866aa2110ee8b883d4c64549a01e173ac94 /plugin/icedteanp/java | |
parent | 60193e3eb63eb578d6e5da3d43830013d1b21211 (diff) |
Fixed possible deadlock for applet->js->applet call with testcase
Diffstat (limited to 'plugin/icedteanp/java')
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginAppletViewer.java | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java index 3feedd6..8aab9ac 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java @@ -181,7 +181,23 @@ public class PluginAppletViewer extends XEmbeddedFrame private SplashPanel splashPanel; - + + private static long REQUEST_TIMEOUT=60000;//60s + + private static void waitForRequestCompletion(PluginCallRequest request) { + try { + if (!request.isDone()) { + request.wait(REQUEST_TIMEOUT); + } + if (!request.isDone()) { + // Do not wait indefinitely to avoid the potential of deadlock + throw new RuntimeException("Possible deadlock, releasing"); + } + } catch (InterruptedException ex) { + throw new RuntimeException("Interrupted waiting for call request.", ex); + } + } + /** * Null constructor to allow instantiation via newInstance() */ @@ -1290,18 +1306,13 @@ public class PluginAppletViewer extends XEmbeddedFrame streamhandler.postCallRequest(request); streamhandler.write(request.getMessage()); - try { - PluginDebug.debug("wait ToString request 1"); - synchronized (request) { - PluginDebug.debug("wait ToString request 2"); - while (request.isDone() == false) - request.wait(); - PluginDebug.debug("wait ToString request 3"); - } - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted waiting for call request.", - e); + PluginDebug.debug("wait ToString request 1"); + synchronized (request) { + PluginDebug.debug("wait ToString request 2"); + waitForRequestCompletion(request); + PluginDebug.debug("wait ToString request 3"); } + PluginDebug.debug(" ToString DONE"); return (String) request.getObject(); } |