motiv-labs / janus

An API Gateway written in Go
https://hellofresh.gitbooks.io/janus
MIT License
2.79k stars 317 forks source link

PT-1163 Fixed memory leak caused by creating eternal goroutines for every new transport #328

Closed vgarvardt closed 6 years ago

vgarvardt commented 6 years ago

What does this PR do?

This PR solves the problem with memory leaking on each reouter reload. The problem was in the transport - each definition created own transport, and each launched infinite go-routine. The solution is the following: do not create transport for each route, reuse one from the registry instead (registry key is being built from transport parameters), and do not launch go-routine, let transport retire "keep-alive" connections using internal transport functionality.

In addition to this there are couple minor changes I did during issue investigation:

One known issue is still not fixed - the way I discovered this memory leak issue is that reflect.DeepEqual() does not work properly when comparing current loaded from Mongo data in our environment. I'm in the process of investigation, but let it be in the next PR.

codecov[bot] commented 6 years ago

Codecov Report

Merging #328 into master will decrease coverage by 0.21%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #328      +/-   ##
==========================================
- Coverage   41.47%   41.25%   -0.22%     
==========================================
  Files          74       74              
  Lines        2486     2499      +13     
==========================================
  Hits         1031     1031              
- Misses       1390     1403      +13     
  Partials       65       65
Impacted Files Coverage Δ
pkg/plugin/oauth2/mongodb_repository.go 0% <ø> (ø) :arrow_up:
pkg/plugin/oauth2/setup.go 7.86% <ø> (ø) :arrow_up:
pkg/router/listen_path_matcher.go 100% <ø> (ø) :arrow_up:
pkg/config/specification.go 61.11% <ø> (ø) :arrow_up:
pkg/api/mongodb_repository.go 0% <0%> (ø) :arrow_up:
pkg/web/options.go 0% <0%> (ø) :arrow_up:
pkg/proxy/register_options.go 0% <0%> (ø) :arrow_up:
pkg/proxy/register.go 0% <0%> (ø) :arrow_up:
pkg/web/provider.go 0% <0%> (ø) :arrow_up:
pkg/plugin/basic/mongodb_repository.go 4.34% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 75dd24e...4c9c3ba. Read the comment docs.