Closed stwonary closed 2 months ago
Just tried with the latest version 0.8.1 and got the same error.
This error would be eliminated by prioritizing the condition of the node being healthy in the check. Here's why:
The early exit strategy, when the nearest node is found to be healthy (as is the case for the first access of a node), would prevent unnecessary checks for if a node is due for a health check. Consequently, if a node's request would resolve in an network error, it would set the health check to false:
By utilizing the setNodeHealthStatus
method, we ensure that the last access timestamp is updated to the current time. This approach prevents the value from being null from that point onwards:
In pull request #62, we address not only the order of checks performed but also add an initial value to a Node when constructed. This addition helps avoid potential null reference errors in the future. Given that there's a single export of the client using a Configuration whose lifetime matches that of the application, setting all nodes' initial access timestamps to their creation time doesn't pose a problem. This approach's effectiveness is demonstrated in the tests provided in the PR.
Please check on 0.9.0
that has just been published.
I’ve just tested version 0.9.0, and everything is working perfectly. Thank you!
Description:
When using the Typesense Java SDK (version 0.8.0) with a cluster setup, I encounter a
NullPointerException
when inserting documents:I believe the problem lies in this condition in
Client.java
:The default value of
isHealthy
istrue
, butlastAccessTimestamp
isnull
, as seen here:https://github.com/typesense/typesense-java/blob/27bacf7937a085ede7306bd57a70d705d6c00c32/src/main/java/org/typesense/resources/Node.java#L23-L42
This results in the
Duration.between()
ApiCall.java:58
method throwing an exception.Steps to Reproduce:
Set up a multi-node cluster with Typesense Cloud:
xxx-1.a1.typesense.net
xxx-2.a1.typesense.net
xxx-3.a1.typesense.net
xxx.a1.typesense.net
Use the Java SDK (version 0.8.0) with the following configuration:
Attempt to insert a document into the
companies
collection.Expected Behavior:
Document insertion should succeed.
Actual Behavior:
A
NullPointerException
occurs due to thelastAccessTimestamp
beingnull
when multiple nodes are used.Metadata:
Typesense Version: 27.0 (Typesense Cloud)
Java SDK Version: 0.8.0