Skip to content

JAVA-5907#1893

Open
strogiyotec wants to merge 1 commit intomongodb:mainfrom
strogiyotec:JAVA-5907
Open

JAVA-5907#1893
strogiyotec wants to merge 1 commit intomongodb:mainfrom
strogiyotec:JAVA-5907

Conversation

@strogiyotec
Copy link
Contributor

@strogiyotec strogiyotec commented Feb 18, 2026

The relevant comment in a different PR that lead to creating this one: #1885 (comment) (the original idea was to do the changes in this PR as part of #1885).

JAVA-5907

@strogiyotec strogiyotec requested a review from a team as a code owner February 18, 2026 23:46
--stacktrace --info --continue ${TESTS} | tee -a logs.txt

if grep -q 'LEAK:' logs.txt ; then
echo "Netty Leak detected, please inspect build log"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for being lazy, but I always miss this error message in evergreen logs, all it does it makes it red, we can also change it and redirect to error output, it can be moved into a separate PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a change in ByteBuf prs to make it standout more. - Lets remove from this PR but I like the idea of making it red as well.

@rozza
Copy link
Member

rozza commented Feb 19, 2026

Could you add some detail to the description of the git commits. Reviewing the git log wouldn't provide any real information regarding this change or its motivations.


@Override
public void execute(final Runnable r) {
executor.execute(()->{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
executor.execute(()->{
executor.execute(() -> {


for (int i = 0; i < 50; i++) {
gridFSService.submit(exportFile(latch, i));
gridFSService.execute(exportFile(latch, i));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we relying on the JVM own built‑in default handler to handle callback exceptions?

Copy link
Member

@stIncMale stIncMale Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We replace ExecutorService.submit with Executor.execute because only the latter allows an exception that originates from the executed task to be propagated as an uncaught exception (submit catches it and places in the returned Future, which we do not inspect). Once there is an uncaught exception, ThreadGroup.uncaughtException is called, which emits the information about the uncaught exception to the standard error stream.

The above happens only if the thread does not have an explicit, UncaughtExceptionHandler, and there is no default uncaught exception handler.

Thus with this change, uncaught exceptions won't stay unnoticed anymore:

  • at the very least the info about them will be emitted to the standard error stream;
  • an application may register the default uncaught exception handler to change that behavior.
    • And it absolutely should. The majority of applications should terminate when a VirtualMachineError happens, because such errors, being unexpected and asynchronous on top of that, may cause application invariants to be violated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our test code is "the application". So ideally, we should register a default uncaught exception handler that logs uncaught exceptions using our logging, and terminates the VM if it's a VirtualMachineError (it should also try and log such errors, but make sure the VM terminates even if logging fails).

I'll create a technical debt ticket for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stIncMale
Copy link
Member

@strogiyotec I updated the PR description so that it points to the ticket, and also to the relevant comment in the previous PR.

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also look at all the places where we call methods of ScheduledExecutorService, and do not handle the exceptions from the returned Futures:

  1. If easily doable, we should handle the exceptions from those Futures. But I suspect, if most if not all cases it is not really doable.
  2. If not, we should make sure that the Runnable/Callables we schedule catch everything, log Exceptions they can't really handle, and handle all Errors by calling Thread.currentThread().getThreadGroup().uncaughtException(e, Thread.currentThread())

Furthermore, everywhere we catch Throwable (we don't explicitly catch Errors or any subtypes, I checked) in production code, we should make sure that if it's an Error:

  1. It is either re-thrown / put into a Future / fed into a callback (if that's what we do) as is, without being wrapped into anything.
  2. Or, if re-throwing is not an supposed to happen, is handled via Thread.currentThread().getThreadGroup().uncaughtException(e, Thread.currentThread()).

The two above suggestions ensure that the default uncaught exception handler configured by an application will have a chance to handle all Errors that originate from our code. And if there no uncaught exception handler is configured, the Errors at least will be handled the same way the Java SE handles all uncaught exceptions by default.

TimeUnit.MILLISECONDS,
c -> group.submit(() -> handler.completed((int) c, attach)),
e -> group.submit(() -> handler.failed(e, attach)));
c -> group.execute(() -> handler.completed((int) c, attach)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code comes from TLS Channel, which we "vendor" as part of the driver, though our vendored code deviates from the original.

@strogiyotec, let's create a TLS Channel issue suggesting this change? Of course, we'll need to explain the reasoning behind it. Or, if you feel especially generous, you could even open a PR for that repo :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me do it

@stIncMale
Copy link
Member

I updated my comment #1893 (review). Since there are no notifications about updates, I am leaving another comment as a way to notify.

@stIncMale stIncMale mentioned this pull request Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments