Skip to content

Add regression tests for the net client close hook registration - #6314

Open
jnbdz wants to merge 1 commit into
eclipse-vertx:masterfrom
SiteNetSoft:issue-6311-netclient-leak-tests
Open

Add regression tests for the net client close hook registration#6314
jnbdz wants to merge 1 commit into
eclipse-vertx:masterfrom
SiteNetSoft:issue-6311-netclient-leak-tests

Conversation

@jnbdz

@jnbdz jnbdz commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Motivation

#6311 reports that a client created with createNetClient() is never released, even after close() completes, so each call leaves one NetClientImpl reachable for the life of the Vert.x instance.

The leak is real but is already fixed on master. Bisecting with the tests in this PR:

ResourceHook.shutdown now calls owner.remove(this) before delegating to the resource, so shutting the client down — explicitly or through the cleaner — unregisters the close hook and the client becomes collectable. That generalised the HTTP client fix from abab114, whose ClientCloseableResource carried the note that it "should somehow get unified and reused".

Nothing covers the net client case, so this adds the missing tests rather than a fix.

Change

Two tests mirroring testFinalizeHttpClientRegisteredWithCloseHook:

  • testFinalizeNetClientRegisteredWithCloseHook — client created inside a verticle, so the owner is the context close future; it also asserts the client does not resurface after undeploy.
  • testFinalizeNetClientRegisteredWithVertxCloseHook — client created with the Vert.x instance as owner, matching the reproducer in the issue.

Both were verified to fail at d9e1080 and pass from 6a0a037 onwards, so they lock in the behaviour rather than merely passing today.

Test

Full VertxTest: 21 tests, 0 failures.

Note

The 5.1 branch does not contain 6a0a037 and still leaks — testFinalizeNetClientRegisteredWithVertxCloseHook fails there at 6b710f6, which matches the 5.1.6 report. I left that out of this PR since the backport is your call; happy to open one against 5.1 if you want it.

Motivation:

Closing a net client did not unregister it from its owner close future, so
every client created with createNetClient() stayed reachable for the life
of the Vert.x instance. This was fixed by 6a0a037, which made the
resource hook remove itself from its owner when shut down, but nothing
covers the net client case.

Changes:

Add two tests mirroring testFinalizeHttpClientRegisteredWithCloseHook, one
for a client created in a verticle context and one for a client created
with the Vert.x instance as owner. Both fail before 6a0a037.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant