You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by "jsinovassin (via GitHub)" <gi...@apache.org> on 2026/02/06 10:55:27 UTC
[PR] UNOMI-930: sync startup log display to avoid to see it twice [unomi]
jsinovassin opened a new pull request, #749:
URL: https://github.com/apache/unomi/pull/749
PR Title format:
https://issues.apache.org/jira/browse/UNOMI-930
**Please** add a meaningful description for your change here
This pull request refines the startup message display logic in the `BundleWatcherImpl` class to ensure thread safety and prevent duplicate messages. The main changes involve introducing a synchronization mechanism and restructuring the startup completion checks.
**Thread safety and startup logic improvements:**
* Added a `startupMessageLock` object and synchronized the startup message display block to prevent concurrent threads from displaying the startup message multiple times. [[1]](diffhunk://#diff-670192d8f4e1ff0120db1c574ff5df8553593f0573a6fdc0345bc437285e7c8bR61-R63) [[2]](diffhunk://#diff-670192d8f4e1ff0120db1c574ff5df8553593f0573a6fdc0345bc437285e7c8bL277-R291)
* Refactored the `checkStartupComplete` method to improve the order and clarity of startup and additional bundle checks, ensuring the scheduler is managed properly and the startup message is displayed only once. [[1]](diffhunk://#diff-670192d8f4e1ff0120db1c574ff5df8553593f0573a6fdc0345bc437285e7c8bL277-R291) [[2]](diffhunk://#diff-670192d8f4e1ff0120db1c574ff5df8553593f0573a6fdc0345bc437285e7c8bR317-R318)
----
**Please** following this checklist to help us incorporate your contribution quickly and easily:
- [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/UNOMI) filed
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
- [ ] Format the pull request title like `[UNOMI-XXX] - Title of the pull request`
- [ ] Provide integration tests for your changes, especially if you are changing the behavior of existing code or adding
significant new parts of code.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
Copy the description to the related JIRA issue
- [ ] Run `mvn clean install -P integration-tests` to make sure basic checks pass. A more thorough check will be
performed on your pull request automatically.
Trivial changes like typos do not require a JIRA issue (javadoc, project build changes, small doc changes, comments...).
If this is your first contribution, you have to read the [Contribution Guidelines](https://unomi.apache.org/contribute.html)
If your pull request is about ~20 lines of code you don't need to sign an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf)
if you are unsure please ask on the developers list.
To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
you have to acknowledge this by using the following check-box.
- [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] UNOMI-930: sync startup log display to avoid to see it twice [unomi]
Posted by "sergehuber (via GitHub)" <gi...@apache.org>.
sergehuber commented on PR #749:
URL: https://github.com/apache/unomi/pull/749#issuecomment-3876557047
It seems the test are failing because we need to update CodeQL, see https://github.blog/changelog/2025-01-10-code-scanning-codeql-action-v2-is-now-deprecated/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] UNOMI-930: sync startup log display to avoid to see it twice [unomi]
Posted by "sergehuber (via GitHub)" <gi...@apache.org>.
sergehuber commented on PR #749:
URL: https://github.com/apache/unomi/pull/749#issuecomment-3880318281
Hi @jsinovassin thanks for the PR.
I found (with some AI help I must admit :)) some tricky bugs. Let me know if you need any clarifications.
Best regards,
Serge...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] UNOMI-930: sync startup log display to avoid to see it twice [unomi]
Posted by "sergehuber (via GitHub)" <gi...@apache.org>.
sergehuber commented on PR #749:
URL: https://github.com/apache/unomi/pull/749#issuecomment-3880193278
Ok I found why the tests were failing we need to update the CodeQL Javascript version. I've done that in the master branch, you should merge that change into your branch so that the checks pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] UNOMI-930: sync startup log display to avoid to see it twice [unomi]
Posted by "jsinovassin (via GitHub)" <gi...@apache.org>.
jsinovassin merged PR #749:
URL: https://github.com/apache/unomi/pull/749
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] UNOMI-930: sync startup log display to avoid to see it twice [unomi]
Posted by "sergehuber (via GitHub)" <gi...@apache.org>.
sergehuber commented on code in PR #749:
URL: https://github.com/apache/unomi/pull/749#discussion_r2789894426
##########
lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcherImpl.java:
##########
Review Comment:
`cancel(true)` should be changed to `cancel(false)` here. To see why, trace the call path:
1. `checkStartupComplete()` calls `startScheduler(getBundleCheckTask())`, which schedules a recurring task via `scheduleWithFixedDelay`.
2. When that task fires, it runs `getBundleCheckTask().run()`, which calls back into `checkStartupComplete()`.
3. `checkStartupComplete()` now starts with `destroyScheduler()`, which calls `scheduledFuture.cancel(true)`.
4. At this point, the thread calling `cancel(true)` *is* the thread running the scheduled task — it is cancelling itself.
The `true` argument means "interrupt if running", which sets the current thread's interrupt flag. The thread then continues executing the rest of `checkStartupComplete()` with its interrupt flag set. Any subsequent interruptible operation in that same execution — in particular, NIO-based log appenders writing to a `FileChannel` — may then throw `ClosedByInterruptException`, which permanently closes the channel and can break logging for the rest of the process lifetime. This is hard to reproduce because it depends on timing and on which logging backend and appenders are configured.
Using `cancel(false)` prevents future scheduled executions without interrupting the current one, which is the intended behavior here.
References:
- [JavaDoc — Future.cancel(boolean)](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/Future.html#cancel(boolean)) ("if the task has already started, then the `mayInterruptIfRunning` parameter determines whether the thread executing this task should be interrupted")
- [JavaDoc — ClosedByInterruptException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/channels/ClosedByInterruptException.html) ("thrown when a thread is interrupted while blocked in an I/O operation upon a channel — the channel is closed as a side-effect")
##########
lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcherImpl.java:
##########
@@ -58,6 +58,9 @@ public class BundleWatcherImpl implements SynchronousBundleListener, ServiceList
private List<ServerInfo> serverInfos = new ArrayList<>();
+ // Lock object to synchronize startup message display
+ private final Object startupMessageLock = new Object();
Review Comment:
`startupMessageAlreadyDisplayed` should be declared `volatile` here, because it is read *outside* the `synchronized` block (line 290) as part of a double-checked locking pattern. Without `volatile`, the Java Memory Model allows a thread to read a stale cached value indefinitely — meaning a thread could keep seeing `false` even after another thread has set it to `true` inside the lock. In practice, stale reads are rare on strongly-ordered architectures like x86 (which is why the bug may not show up during development), but they are much more frequent on weakly-ordered architectures like ARM — commonly used in cloud/container deployments. Adding `volatile` guarantees that every write is immediately visible to all threads, which is what makes the outer check reliable.
References:
- [CERT Oracle Coding Standard — LCK10-J: Use a correct form of the double-checked locking idiom](https://wiki.sei.cmu.edu/confluence/display/java/LCK10-J.+Use+a+correct+form+of+the+double-checked+locking+idiom)
- [Oracle Java Tutorial — Atomic Access](https://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html)
- [JLS §17.4 — Memory Model](https://docs.oracle.com/javase/specs/jls/se17/html/jls-17.html#jls-17.4) (defines the happens-before rules that govern when writes become visible across threads)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org