From b6e4f053a30842ef96c369a97ce78a36d499f6c0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Jan 2018 14:39:24 -0800 Subject: [PATCH] Fix lock rpc server maintenance loop go-routine leak (#5423) The problem was after the globalServiceDoneCh receives a message, we cleanly stop the ticker as expected. But the go-routine where the `select` loop is running is never returned from. The stage at which point this may occur i.e server is being restarted, doesn't seriously affect servers usage. But any build up like this on server has consequences as the new functionality would come in future. --- cmd/lock-rpc-server.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/lock-rpc-server.go b/cmd/lock-rpc-server.go index 77c738f32..92d68e514 100644 --- a/cmd/lock-rpc-server.go +++ b/cmd/lock-rpc-server.go @@ -76,11 +76,12 @@ func startLockMaintenance(lockServers []*lockServer) { for { // Verifies every minute for locks held more than 2minutes. select { + case <-globalServiceDoneCh: + // Stop the timer upon service closure and cleanup the go-routine. + ticker.Stop() + return case <-ticker.C: lk.lockMaintenance(lockValidityCheckInterval) - case <-globalServiceDoneCh: - // Stop the timer. - ticker.Stop() } } }(locker)