#http.transport creating goroutines and not removing them upon client.do request
22 messages · Page 1 of 1 (latest)
You need to set more. Timeouts should be set.
Don't leave any timeout attributes set to 0.
Particularly, you will need
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
to clean up the idle connections
The other timeouts are necessary as well since they could get stuck in various different states and keep Goroutines alive
this will work fine right? ```go
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
},
}```
As a note,I believe the default MaxIdleConnsPerHost is 2, but yeah that should work
damn that worked
thx
i been tryna find the memory leak in my code for hours just to find that
thx
Thought there was going to be more too it as well, but I'm glad it's fixed! Sorry for the extra run into making a thread
ye i thought there would be more to it aswell ngl but ye thx
Might want to take a close look at the number of idle connections that you accept and how long you want to idle. You also want to think about the other end and what they have to face. 90 seconds of nothing is pretty long. So depending on the purpose and the protocol, you'd want to be more conservative about the values that you set.
apparently after implementing it into some older versions that ik work just because they arent a complete mess from my testing the issue is still there with threads constantly spawning in with transport and when transport gets removed it doesnt happen anymore so im not sure what it is now because it was a completely messed up version i tested it on
it starts up goroutines without closing them like before except with all this new timeout stuff and only with the transport there
nvm all i had to do was add continueChallengeResponse.Body.Close()
to a request for some reason
ye that seems to have worked but ofc my memory leak still exists :,)
Yes, close the body when you're done with it. Even write your code so that it's a deferred call to the close method. This ensure that it will be closed even if the rest of the code causes a panic (which you should avoid).