Skip to content

Simplify Client.Do function and lock usage#2038

Merged
erikdubbelboer merged 2 commits intovalyala:masterfrom
byte0o:master
Jul 19, 2025
Merged

Simplify Client.Do function and lock usage#2038
erikdubbelboer merged 2 commits intovalyala:masterfrom
byte0o:master

Conversation

@byte0o
Copy link
Contributor

@byte0o byte0o commented Jul 15, 2025

  1. Simplify the Client.Do function, extract the acquisition of HostClient object into a separate function, and simplify the lock code
  2. Remove redundant code from the AcquireReader and AcquireWriter functions of HostClient

byte0o added 2 commits July 15, 2025 11:26
1. Simplify the Client.Do function, extract the acquisition of HostClient object into a separate function, and simplify the lock code
2. Remove redundant code from the AcquireReader and AcquireWriter functions of HostClient
@byte0o
Copy link
Contributor Author

byte0o commented Jul 15, 2025

@erikdubbelboer Please help me rerun the test. There is no problem running it in my fork branch. I don't know why there is a problem running the test here.

@erikdubbelboer erikdubbelboer requested a review from Copilot July 15, 2025 10:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the request handling in Client.Do by extracting host lookup and creation into a dedicated helper and streamlines lock usage. It also removes duplicate buffer-initialization branches in HostClient’s reader and writer acquisition methods.

  • Extracts hostClient helper to centralize map access and locking
  • Moves pendingClientRequests atomic increments into the top-level Do method
  • Simplifies AcquireWriter and AcquireReader by consolidating nil-check branches
Comments suppressed due to low confidence (1)

client.go:526

  • [nitpick] The helper hostClient retrieves or initializes a HostClient. Renaming it to getHostClient (or similar) could make its intent clearer and align with common getter naming conventions.
func (c *Client) hostClient(host []byte, isTLS bool) (*HostClient, error) {

@erikdubbelboer erikdubbelboer merged commit 7e15e31 into valyala:master Jul 19, 2025
10 of 11 checks passed
@erikdubbelboer
Copy link
Collaborator

Thanks!

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