From 6c7d15d9d36e96b48e33f2a32ad89dcc01d77d0a Mon Sep 17 00:00:00 2001 From: amaitland Date: Sat, 27 Jul 2019 21:49:49 +1000 Subject: [PATCH] WcfEnabledSubProcess - OnBrowserDestroyed add null checks and log msg if WCF was null It's likely the WCF host didn't start and some break points should be added in ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost to catch the actual exception. We're not logging as it causes too many false positives as it's expected there will be errors when browser is created then rapidly Disposed. Resolves #2839 --- .../WcfEnabledSubProcess.cpp | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.cpp b/CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.cpp index 029f5e300c..ced1f83c3b 100644 --- a/CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.cpp +++ b/CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.cpp @@ -58,34 +58,46 @@ namespace CefSharp { auto channelFactory = browser->ChannelFactory; - try + //Add null check for issue https://github.com/cefsharp/CefSharp/issues/2839 + if (channelFactory == nullptr) { - if (channelFactory->State == CommunicationState::Opened) - { - channelFactory->Close(); - } + LOG(ERROR) << "WcfEnabledSubProcess::OnBrowserDestroyed - browser->ChannelFactory was unexpectedly null, see https://github.com/cefsharp/CefSharp/issues/2839 for some debugging tips."; } - catch (Exception^) + else { - channelFactory->Abort(); + try + { + if (channelFactory->State == CommunicationState::Opened) + { + channelFactory->Close(); + } + } + catch (Exception^) + { + channelFactory->Abort(); + } } - auto clientChannel = ((IClientChannel^)browser->BrowserProcess); - - try + //Add null check for issue https://github.com/cefsharp/CefSharp/issues/2839 + if (browser->BrowserProcess != nullptr) { - if (clientChannel->State == CommunicationState::Opened) + auto clientChannel = ((IClientChannel^)browser->BrowserProcess); + + try { - clientChannel->Close(); + if (clientChannel->State == CommunicationState::Opened) + { + clientChannel->Close(); + } + } + catch (Exception^) + { + clientChannel->Abort(); } - } - catch (Exception^) - { - clientChannel->Abort(); } browser->ChannelFactory = nullptr; browser->BrowserProcess = nullptr; } } -} \ No newline at end of file +}