CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

WPF - WritableBitmapRenderHandle.CreateOrUpdateBitmap possible lock contention

Open ghost opened this issue 5 years ago • 5 comments

  • Environment Information

    • CefSharp WPF v86.0.241
    • Windows 10 x64
    • .Net Framework v4.8
  • Issue Description Drag and drop functionality of a web page running React DnD (https://react-dnd.github.io/react-dnd) causes the entire application running the browser to hang in semi rare cases (never recovering). Stack tracing with dotTrace reveals a possible lock contention in the WPF library, specifically at the CefSharp.WPF.Rendering.WritableBitmapRenderHandle.CreateOrUpdateBitmap() method.

image

  • Steps to reproduce

    • Navigate to a web page that has internal drag and drop functionality (aka. it is possible to drag and drop content within the web page), preferably a web page that uses React DnD in the backend to handle dragging.
    • Drag and drop content within the web page repeatedly.
    • In some cases this should then hang and leave the browser unresponsive.
  • Additional Information

    • The script (TypeScript) that handles dragging in our case: https://pastebin.com/VnaME63a (somewhat obfuscated for IP reasons)
    • dotTrace of the suspected lock contention: image

ghost avatar Mar 18 '21 12:03 ghost

I'm not familiar with dotTrace so your screenshots are largely meaningless to me. Are you saying there's a deadlock? Which line exactly? (Link to the source on GitHub please).


You can integrate CEF into your apps existing message loop to avoid locking.

https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop You can modify the source to see a demo https://github.com/cefsharp/CefSharp/blob/cefsharp/88/CefSharp.Wpf.Example/App.xaml.cs#L28

amaitland avatar Mar 18 '21 19:03 amaitland

The deadlock reported by dotTrace occurs in the WritableBitmapRenderHandler.CreateOrUpdateBitmap(), a method which contains two locks (the later dispatched from within the former): https://github.com/cefsharp/CefSharp/blob/516de14af663e5bd2ea7841e63b82f9c93042190/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs#L46 https://github.com/cefsharp/CefSharp/blob/516de14af663e5bd2ea7841e63b82f9c93042190/CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs#L79

Judging by the mention of a Dispatcher in the dotTrace stack trace:

image

The later lock invoked on row 79 seems to be the origin.

Jonas-Axelsson avatar Mar 22 '21 09:03 Jonas-Axelsson

WritableBitmapRenderHandler.CreateOrUpdateBitmap(), a method which contains two locks (the later dispatched from within the former):

Effectively they're two different functions called on different threads, one if them is just anonymous inline function.

Pull requests welcome.

amaitland avatar Mar 22 '21 10:03 amaitland

See https://github.com/cefsharp/CefSharp/issues/2275#issuecomment-609536970 for details on one of the other rendering implentations, this might be another alternative.

amaitland avatar Mar 27 '21 10:03 amaitland

Closing as this has been inactive for some time. No other reports have been received.

If this reproduces with the current supported version then this can be reopened.

amaitland avatar Sep 21 '22 01:09 amaitland