From 6f3a45b75f33f2c82e8e5858ad14212734fffb07 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Mon, 10 Aug 2020 16:38:37 +0200 Subject: [PATCH] etcd: make embedded etcd context cancelable --- channeldb/kvdb/etcd/embed.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/channeldb/kvdb/etcd/embed.go b/channeldb/kvdb/etcd/embed.go index 3e6b9b16..d99b901e 100644 --- a/channeldb/kvdb/etcd/embed.go +++ b/channeldb/kvdb/etcd/embed.go @@ -64,8 +64,10 @@ func NewEmbeddedEtcdInstance(path string) (*BackendConfig, func(), error) { fmt.Errorf("etcd failed to start after: %v", readyTimeout) } + ctx, cancel := context.WithCancel(context.Background()) + connConfig := &BackendConfig{ - Ctx: context.Background(), + Ctx: ctx, Host: "http://" + peerURL, User: "user", Pass: "pass", @@ -73,6 +75,7 @@ func NewEmbeddedEtcdInstance(path string) (*BackendConfig, func(), error) { } return connConfig, func() { + cancel() etcd.Close() }, nil }