From 6d4766595c5c60c49d3be08cf87a1b792e46e63d Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 4 Aug 2020 15:48:57 +0200 Subject: [PATCH] Use a single GRPC new client instance The client is already using a connection pool, so we should not instantiate it multiple times as it causes connections to stay open and makes file descriptors leak. Co-authored-by: "A.Unger" --- changelog/unreleased/fix-file-descriptor-leak.md | 7 +++++++ pkg/service/v0/service.go | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/fix-file-descriptor-leak.md diff --git a/changelog/unreleased/fix-file-descriptor-leak.md b/changelog/unreleased/fix-file-descriptor-leak.md new file mode 100644 index 000000000..cad17c996 --- /dev/null +++ b/changelog/unreleased/fix-file-descriptor-leak.md @@ -0,0 +1,7 @@ +Bugfix: Fix file descriptor leak + +Only use a single instance of go-micro's GRPC client as it already +does connection pooling. This prevents connection and file descriptor leaks. + +https://github.com/owncloud/ocis-accounts/issues/79 +https://github.com/owncloud/ocis-ocs/pull/29 diff --git a/pkg/service/v0/service.go b/pkg/service/v0/service.go index 8bc38b038..61d3912e1 100644 --- a/pkg/service/v0/service.go +++ b/pkg/service/v0/service.go @@ -16,6 +16,8 @@ import ( "github.com/owncloud/ocis-pkg/v2/log" ) +var defaultClient = grpc.NewClient() + // Service defines the extension handlers. type Service interface { ServeHTTP(http.ResponseWriter, *http.Request) @@ -100,9 +102,9 @@ func (o Ocs) NotFound(w http.ResponseWriter, r *http.Request) { } func (o Ocs) getAccountService() accounts.AccountsService { - return accounts.NewAccountsService("com.owncloud.api.accounts", grpc.NewClient()) + return accounts.NewAccountsService("com.owncloud.api.accounts", defaultClient) } func (o Ocs) getGroupsService() accounts.GroupsService { - return accounts.NewGroupsService("com.owncloud.api.accounts", grpc.NewClient()) + return accounts.NewGroupsService("com.owncloud.api.accounts", defaultClient) }