-
Notifications
You must be signed in to change notification settings - Fork 142
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
Application uses default HTTP Client #48
Comments
hi @shlokgilda can share example of it. It will give more clarification. |
Sure! IssueGo's default http.Client configures a timeout that short-circuits long-running connections. The default for this value is 0, which is interpreted as “no timeout”. Thus, if the external API service we are calling faces an outrage, the default http.Client would fail. This would cause our connection attempt to hang and they will continue to hang for as long as the malfunctioning server decides to wait. Because API calls were being made to serve user requests, this caused the goroutines serving user requests to hang as well. Once enough users hit the API servicers page, the app fell over, most likely due to resource limits being reached. For example:
When we run this program, it will make a request to a server that will sleep for an hour. Consequently, the program will wait for one hour and then exit. SolutionWe could define a custom http.Client with a defined timeout for our usecase.
This sets a 10 second timeout on requests made to the endpoint. If the API server exceeds the timeout, Get() will return with an error. All in all, a malfunctioning malicious service can hang on to our connection forever, potentially starving our application. |
okay lets work on it. lets figure it out how much time we need to set as gocloud will be used production. |
All right. Does this mean refactoring the previous code as well? |
wait we need to make sure this work for all cloud providers . |
All right! |
use start with default http.Client |
All right. Thanks |
The application uses Go's default HTTP client. However, Go’s http package doesn’t specify request timeouts by default, allowing services to hijack our goroutines. Shouldn't we consider the use of a custom http.Client when connecting to the external APIs?
The text was updated successfully, but these errors were encountered: