Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

popover race condition / thread-unsafe code #6838

Open
mvysny opened this issue Nov 20, 2024 · 0 comments
Open

popover race condition / thread-unsafe code #6838

mvysny opened this issue Nov 20, 2024 · 0 comments

Comments

@mvysny
Copy link
Member

mvysny commented Nov 20, 2024

Description

There is a race condition in Popover static functions. If multiple threads call Popover.setDefaultHideDelay() at the same time, that can result in multiple calls to applyConfiguration() and multiple registrations of UI init listener.

The easiest way is to mark all static set*() functions as synchronized. Alternatively, you can use AtomicInteger for all static fields (don't forget to make them final!) and use uiInitListenerRegistered.compareAndSet() in applyConfiguration().

Expected outcome

The UI Init Listener is registered at most once, regardless of how many threads call Popover static functions at the same time.

Alternatively, tell the programmer to call those static functions in a service init listener (which is called exactly once), or from a Spring singleton - but this is more complex and more demanding on the user.

Minimal reproducible example

As is the nature of threading bugs, they are not easy to reproduce. I can create an example program though if you need one 👍

Steps to reproduce

  1. Create an executor with 10 threads; use CountdownLatch to start them at the same time, then start setting the default Focus Delay in a loop. Alternatively, set default focus delay in a session init listener then start DDOS on the web server, but this is harder.
  2. Observe that multiple UI init listeners are registered, because of race condition.

Environment

Vaadin version(s): 24.5.5+

Browsers

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants