Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MilvusClientV2Pool.getClient is null sometimes when using client pool #1118

Open
dingle66 opened this issue Oct 17, 2024 · 3 comments
Open

Comments

@dingle66
Copy link

MilvusClientV2Pool milvusClientV2Pool = new MilvusClientV2Pool(poolConfig, connectConfig);
milvusClientV2Pool.getClient is null occurs sometimes!

@yhmo
Copy link
Contributor

yhmo commented Oct 18, 2024

public T getClient(String key) {

The ClientPool could return null for getClient() method:

    public T getClient(String key) {
        try {
            return clientPool.borrowObject(key);
        } catch (Exception e) {
            System.out.println("Failed to get client, exception: " + e.getMessage());
            return null;
        }
    }

I didn't throw an exception here, do you think it is necessary to throw the error? In my opinion, when user gets a null value, he can check the returned value and recall the getClient() again.

The client.Pool is a GenericKeyedObjectPool. The borrowObject() method internally has a timeout value to wait for a client to be created. The timeout value can be configured by PoolConfig.maxBlockWaitDuration:

poolConfig.setMaxWait(config.getMaxBlockWaitDuration());

The default value of maxBlockWaitDuration is 3 seconds.
Sometimes the client could not be created in 3 seconds, which might caused by network issues or milvus server being too busy to respond. You can increase this value to observe.

@xiaofan-luan
Copy link
Contributor

public T getClient(String key) {

The ClientPool could return null for getClient() method:

    public T getClient(String key) {
        try {
            return clientPool.borrowObject(key);
        } catch (Exception e) {
            System.out.println("Failed to get client, exception: " + e.getMessage());
            return null;
        }
    }

I didn't throw an exception here, do you think it is necessary to throw the error? In my opinion, when user gets a null value, he can check the returned value and recall the getClient() again.

The client.Pool is a GenericKeyedObjectPool. The borrowObject() method internally has a timeout value to wait for a client to be created. The timeout value can be configured by PoolConfig.maxBlockWaitDuration:

poolConfig.setMaxWait(config.getMaxBlockWaitDuration());

The default value of maxBlockWaitDuration is 3 seconds. Sometimes the client could not be created in 3 seconds, which might caused by network issues or milvus server being too busy to respond. You can increase this value to observe.

I think the right thing is to throw error.
For all java users, exceptions is the only thing need to be handled and return null doesn't really make sense to me

@yhmo
Copy link
Contributor

yhmo commented Nov 5, 2024

Fixed by this pr: https://github.com/milvus-io/milvus-sdk-java/pull/1170/files
The exception thrown from GenericKeyedObjectPool is encapsulated by MilvusClientException and thrown out to users.

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

No branches or pull requests

3 participants