Skip to content

fix: Fail on multiple executors only when the executor is accessed - #21839

Merged
mshabarov merged 2 commits into
mainfrom
not-fail-for-multiple-executors
Jul 4, 2025
Merged

mshabarov merged 2 commits into
mainfrom
not-fail-for-multiple-executors

Conversation

@mshabarov

Copy link
Copy Markdown
Contributor

Does not fail eagerly if a Spring app has multiple TaskExecutor bean (without VaadinTaskExecutor qualifier).
Instead it fails when an app tries to access VaadinService.getExecutor() directly or via using a feature that uses this executor (currently the signals preview).

Fixes #21811

@sonarqubecloud

sonarqubecloud Bot commented Jul 4, 2025

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

Test Results

1 232 files  ±0  1 232 suites  ±0   1h 14m 31s ⏱️ + 1m 5s
8 482 tests +2  8 425 ✅ +2  57 💤 ±0  0 ❌ ±0 
8 844 runs  ±0  8 780 ✅ +1  64 💤  - 1  0 ❌ ±0 

Results for commit fd22883. ± Comparison against base commit b053557.

This pull request removes 2 and adds 4 tests. Note that renamed tests count towards both.
com.vaadin.flow.spring.service.SpringVaadinServiceExecutorTest ‑ init_multipleNamedTaskExecutors_throws
com.vaadin.flow.spring.service.SpringVaadinServiceExecutorTest ‑ init_multipleUnnamedTaskExecutors_throws
com.vaadin.flow.spring.service.SpringVaadinServiceExecutorTest ‑ init_multipleNamedTaskExecutors_executorAccessed_throws
com.vaadin.flow.spring.service.SpringVaadinServiceExecutorTest ‑ init_multipleNamedTaskExecutors_executorNotAccessed_doesnThrow
com.vaadin.flow.spring.service.SpringVaadinServiceExecutorTest ‑ init_multipleUnnamedTaskExecutors_executorAccessed_throws
com.vaadin.flow.spring.service.SpringVaadinServiceExecutorTest ‑ init_multipleUnnamedTaskExecutors_executorNotAccessed_doesntThrow

@Legioth

Legioth commented Jul 4, 2025 •

Copy link
Copy Markdown
Member

From what I see, this approach bypasses the possibility of bypassing conflicting Spring beans through serviceInitEvent.setExecutor since the getter will run the logic from SpringVaadinServletService even if the value from that class wouldn't be used.

As an alternative approach, we could maybe create a placeholder executor instance where execute always throws the exception instead of making getExecutor() throw?

@mshabarov

mshabarov commented Jul 4, 2025 •

Copy link
Copy Markdown
Contributor Author

From what I see, this approach bypasses the possibility of bypassing conflicting Spring beans through serviceInitEvent.setExecutor since the getter will run the logic from SpringVaadinServletService even if the value from that class wouldn't be used.

Did not get this.
If you set an executor via serviceInitEvent.setExecutor, then the SpringVaadinServletService.createDefaultExecutor should not run at all meaning that the multiple beans detection is skipped.

Then the throw block in SpringVaadinServletService.getExecutor will be also skipped as the multipleExecutorsCandidates is null.

As an alternative approach, we could maybe create a placeholder executor instance where execute always throws the exception instead of making getExecutor() throw?

That can be an option, but in that case the stack trace may be less readable and also you spot this when a signal will try to execute something at runtime. I'd prefer an exception during initialisation.

@Legioth

Legioth commented Jul 4, 2025

Copy link
Copy Markdown
Member

Did not get this.
If you set an executor via serviceInitEvent.setExecutor, then the SpringVaadinServletService.createDefaultExecutor should not run at all meaning that the multiple beans detection is skipped.

If that's the case, then I do indeed prefer this approach excactly because of the clearer stacktraces. I was for some reason assuming the logic in SpringVaadinServletService would always run.

@mshabarov

Copy link
Copy Markdown
Contributor Author

My statement was based on

this.executor = event.getExecutor()
    .orElseGet(this::createDefaultExecutor);

in VaadinService.init that is the only place where the default executor is accessed.

So Vaadin either uses the one from serviceInitEvent or makes this multi executor detection (for Spring).

@mshabarov
mshabarov merged commit f2b8a20 into main Jul 4, 2025
@mshabarov
mshabarov deleted the not-fail-for-multiple-executors branch July 4, 2025 13:14
vaadin-bot pushed a commit that referenced this pull request Jul 4, 2025
…21839)

Does not fail eagerly if a Spring app has multiple TaskExecutor bean (without VaadinTaskExecutor qualifier).
Instead it fails when an app tries to access VaadinService.getExecutor() directly or via using a feature that uses this executor (currently the signals preview).

Fixes #21811
vaadin-bot pushed a commit that referenced this pull request Jul 4, 2025
…21839)

Does not fail eagerly if a Spring app has multiple TaskExecutor bean (without VaadinTaskExecutor qualifier).
Instead it fails when an app tries to access VaadinService.getExecutor() directly or via using a feature that uses this executor (currently the signals preview).

Fixes #21811
vaadin-bot added a commit that referenced this pull request Jul 4, 2025
…21839) (#21843)

Does not fail eagerly if a Spring app has multiple TaskExecutor bean (without VaadinTaskExecutor qualifier).
Instead it fails when an app tries to access VaadinService.getExecutor() directly or via using a feature that uses this executor (currently the signals preview).

Fixes #21811

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
vaadin-bot added a commit that referenced this pull request Jul 4, 2025
…21839) (#21844)

Does not fail eagerly if a Spring app has multiple TaskExecutor bean (without VaadinTaskExecutor qualifier).
Instead it fails when an app tries to access VaadinService.getExecutor() directly or via using a feature that uses this executor (currently the signals preview).

Fixes #21811

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
Copilot AI pushed a commit that referenced this pull request Oct 1, 2025
…21839)

Does not fail eagerly if a Spring app has multiple TaskExecutor bean (without VaadinTaskExecutor qualifier).
Instead it fails when an app tries to access VaadinService.getExecutor() directly or via using a feature that uses this executor (currently the signals preview).

Fixes #21811
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't fail eagerly for conflicting task executors

4 participants