vugu / vugu

Vugu: A modern UI library for Go+WebAssembly (experimental)
https://www.vugu.org
MIT License
4.8k stars 175 forks source link

Deadlock in event handling when using Chrome #229

Open zoltanmakra opened 2 years ago

zoltanmakra commented 2 years ago

Describe the bug The issue can be reproduced in Vugu Playground.

Steps to reproduce:

  1. Use Chrome
  2. Click on the label (Click here)
  3. Type something and press Enter (or ESC)
  4. UI stops with deadlock

Software Versions Vugu version: current master Go version: 1.18 Browser and version: Chrome Version 100.0.4896.127 (Official Build) (64-bit)

Additional Notes I think the root cause of the issue is that Chrome fires the 'onblur' event in the rendering phase. The vugu event handler locks the renderer in the event handler - but it causes deadlock if the JS thread is blocked. A simple solution is to put the event handling in a goroutine. Example

bradleypeabody commented 2 years ago

Interesting, and thanks for taking the time to write this up. Just a quick observation from fiddling with this for a bit: If I remove event.EventSummary() then I cannot reproduce the issue. I'm not entirely sure why though, since the event summary is already converted into primitive types and it's entire purpose is to provide context of the event without having to call back into the JS environment.

To your point, it definitely seems like something in there is calling back into the JS environment during the event handling, which is then firing another event, which then deadlocks.

Possibly that whole thing just need to be made more robust by having be tolerant to that scenario, although again I think it's key to track down how that is occurring here, since it is not obvious.