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

feat(wallet): add timeout client connection #1396

Merged
merged 9 commits into from
Jul 8, 2024

Conversation

Ja7ad
Copy link
Contributor

@Ja7ad Ja7ad commented Jul 3, 2024

Description

This PR introduces a client timeout for connections when dialing to the server. The primary goal is to prevent delays during query retrieval by setting a maximum duration for establishing a connection. This ensures that if a server is unresponsive or slow, the client will not hang indefinitely, thereby improving the overall responsiveness and reliability of the application.

@Ja7ad Ja7ad requested a review from b00f July 3, 2024 08:25
@Ja7ad Ja7ad requested a review from kehiy July 3, 2024 08:30
Copy link
Contributor

@kehiy kehiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this work in GUI wallet as well?

@kehiy
Copy link
Contributor

kehiy commented Jul 3, 2024

@Ja7ad I've tested it manually with 1 second as timeout but it took 24 seconds to respond to me.

My command:

./pactus-wallet address balance pc1zvchrej8nwfgvsduw47r4qmss5u25kvls2fx8e6 --timeout 1 

Shouldn't it return a timeout error?

wallet/client.go Outdated Show resolved Hide resolved
@Ja7ad
Copy link
Contributor Author

Ja7ad commented Jul 3, 2024

@Ja7ad I've tested it manually with 1 second as timeout but it took 24 seconds to respond to me.

My command:

./pactus-wallet address balance pc1zvchrej8nwfgvsduw47r4qmss5u25kvls2fx8e6 --timeout 1 

Shouldn't it return a timeout error?

This timeout duration for dialing client, gRPC client is immediately and connecting the server happens in background.

When call GetBlockchainInfo client started to dialing and call RPC method.

If server got timeout, try to create new client with other servers.

@kehiy
Copy link
Contributor

kehiy commented Jul 3, 2024

@Ja7ad So, with only 7 servers, and 1-second timeout after 7 seconds I have to get data or timeout or can't connect to servers.

Here is the servers list:

"mainnet": [
        "localhost:50051",
        "bootstrap1.pactus.org:50051",
        "bootstrap2.pactus.org:50051",
        "bootstrap3.pactus.org:50051",
        "bootstrap4.pactus.org:50051",
        "65.109.234.125:50051",
        "157.90.111.140:50051"
]

But it took 24 seconds in my case, am I wrong?

The main thing: we are applying timeout on each request or only when we connect to a server?

@Ja7ad
Copy link
Contributor Author

Ja7ad commented Jul 3, 2024

@Ja7ad so, with only 7 server, and 1 second timeout after 7 second I have to get data or timeout or can't connect to servers.

Here is the servers list:

"mainnet": [
        "localhost:50051",
        "bootstrap1.pactus.org:50051",
        "bootstrap2.pactus.org:50051",
        "bootstrap3.pactus.org:50051",
        "bootstrap4.pactus.org:50051",
        "65.109.234.125:50051",
        "157.90.111.140:50051"
]

But it took 24 seconds in my case, am I wrong?

This timeout is when dialing not query.

You connected to 1 server before 1 second timeout, but this server have delay on query.

@kehiy
Copy link
Contributor

kehiy commented Jul 4, 2024

@Ja7ad our goal is to reduce the latency or just get a timeout. what do you think if we apply the timeout to queries as well? as we defined it on Trello task?

The rest looks good to me, we can merge it.

@Ja7ad
Copy link
Contributor Author

Ja7ad commented Jul 4, 2024

@Ja7ad our goal is to reduce the latency or just get a timeout. what do you think if we apply the timeout to queries as well? as we defined it on Trello task?

The rest looks good to me, we can merge it.

Our delay is on when dialing to find the best server, in connect function.

@kehiy
Copy link
Contributor

kehiy commented Jul 4, 2024

@Ja7ad but based on my manual test, the process is still slow but there is no timeout error. which is not the same as our goal.

cmd/wallet/main.go Outdated Show resolved Hide resolved
wallet/client.go Outdated Show resolved Hide resolved
wallet/client.go Outdated Show resolved Hide resolved
wallet/wallet.go Outdated Show resolved Hide resolved
wallet/client.go Outdated Show resolved Hide resolved
@Ja7ad
Copy link
Contributor Author

Ja7ad commented Jul 7, 2024

@b00f done

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

Attention: Patch coverage is 45.94595% with 20 lines in your changes missing coverage. Please review.

Project coverage is 76.42%. Comparing base (472c347) to head (ada1aff).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1396      +/-   ##
==========================================
- Coverage   77.16%   76.42%   -0.74%     
==========================================
  Files         233      213      -20     
  Lines       11941    10978     -963     
==========================================
- Hits         9214     8390     -824     
+ Misses       2305     2196     -109     
+ Partials      422      392      -30     

@Ja7ad Ja7ad added this to the v1.4.0 milestone Jul 7, 2024
@b00f b00f merged commit a32d37c into pactus-project:main Jul 8, 2024
11 of 12 checks passed
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

Successfully merging this pull request may close these issues.

3 participants