opensearch-project / opensearch-project/opensearch-java

[BUG]why OpenSearchGenericClient.withTransportOptions(TransportOptions transportOptions) create a new OpenSearchGenericClient object?

Open
#1,694 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
165
Forks
250
Avg merge
1d 18h
Merged PRs (30d)
26

Description

What is the bug?

A clear and concise description of the bug.
OpenSearchGenericClient.withTransportOptions(TransportOptions transportOptions).execute(Request request) create a new OpenSearchGenericClient in every execution.

How can one reproduce the bug?

Steps to reproduce the behavior.

  1. Create OpenSearchTransport with global connection timeout settings. And create OpenSearchGenericClient.
  2. Most requests use global connection timeout settings to access the server by OpenSearchGenericClient.execute(Request request).
  3. Some special requests need custom connection timeout settings to access the server by OpenSearchGenericClient.withTransportOptions(TransportOptions transportOptions).execute(Request request).

private static void search(OpenSearchGenericClient client, String endPoint, long connectionTimout) {
Request request = Requests.create("GET", endPoint, null, Map.of(), null);
ApacheHttpClient5Options transportOptions = ApacheHttpClient5Options.DEFAULT.toBuilder()
.setRequestConfig(
RequestConfig.custom().setConnectionRequestTimeout(connectionTimout, TimeUnit.SECONDS).build())
.build();
try {
// each request set connectionTimeout independently
Response response = client.withTransportOptions(transportOptions).execute(request);
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

What is the expected behavior?

client.withTransportOptions(transportOptions) create a new OpenSearchGenericClient, each request will create a new client object, it will create many temp client objects

What is your host/environment?

linux

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Contributor guide

Open the contributing guide

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.

Research direction

Start at OpenSearchGenericClient.withTransportOptions(TransportOptions) and its execute(Request) path; no file or test is named in the report. Trace how transport options are applied and inspect nearby client tests. Done should establish whether each call allocates a client and address the reported per-request allocation without changing the timeout behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.