Skip to content

Potential Misuse of Use() Method Causing High Latency #69

@mehdijoafshani

Description

@mehdijoafshani

Hi,

Lately, I faced an issue in our project that I thought would be worth logging here.

Scenario

Our service acts as a proxy, receiving many requests and routing them to other services.

We had a function (function1) that worked fine:

// ...
myClient.
    Post().
    Use(headers.Set("header-k", value)).
    JSON(postRequest)
// ...

Recently, a similar function (function2) was added to call another service. However, logs showed that this function was taking too long, even though server logs indicated low latency. Upon closer inspection, the implementation looked very similar, with just a minor change:

// ...other code
myClient.
    Use(headers.Set("header-k", value)).
    Post().
    JSON(postRequest)
// ... other code

What Happened?

In function1, the Use() method is applied only to the request, which is fine.
In function2, however, Use() is applied to the global client, affecting all requests and causing mutex locks. This resulted in a long queue and high latency on the client side.

Why This Matters

Clearly, the mistake in function2 was an oversight. However, it was hard to catch in PR reviews and caused significant performance issues.

Suggestion

I believe it would be beneficial to improve the documentation to clarify how Use() works and warn developers about potential misuse. This could help prevent similar issues in the future.

Would love to hear your thoughts on this! Thanks. 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions