Idle connection thread is not a daemon, so the JVM cannot exit without close()

Open Beginner friendly
#241 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
networking

Research direction

Start in httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/HttpClientFactoryImpl.java: the constructor at lines 60-61 creates and starts the idle connection monitor thread, and the thread class at lines 220-246 never calls setDaemon. Reproduce by running a small main that builds a B2StorageClient with the default factory and returns without close(), then check whether the JVM stays alive. Done when the JVM exits on its own and the existing tests still pass after the thread is marked as a daemon before start().

Written by the indexing model from the issue text.

Description

What happens

HttpClientFactoryImpl starts an IdleConnectionMonitorThread in its constructor, and the thread is never marked as a daemon. A program that creates a client and does not call close() on it keeps running after main returns, with no message. Calling close() is documented as the right way, but the hang is easy to hit in short programs and tests.

Where

httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/HttpClientFactoryImpl.java:60-61 (constructor creates and starts the thread) and :220-246 (the thread class, which does not call setDaemon(true); no setDaemon call exists anywhere in the repository).

Why it matters

Impact: Left behind (a running thread keeps the process alive), silent. Severity: Medium, because it only happens when the caller never closes the client (an unusual condition, since B2StorageClientImpl documents that close() should be called) and the workaround is to call close().

How to check

Found by reading the code, not reproduced. Read the constructor and the thread class. Running a small main that builds a B2StorageClient with the default factory and returns without closing it should leave the JVM running (a thread dump would show the monitor thread). Calling setDaemon(true) before start() would let the JVM exit.

Version

Seen at v6.5.0. Present on the default branch: present.

Dominant language
Java
Stars
103
Forks
23
Avg merge
5d 8h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Backblaze/b2-sdk-java

All issues in Backblaze/b2-sdk-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.