Browse code

Fix gcplogs memory/connection leak

The cloud logging client should be closed when the log driver is closed. Otherwise dockerd will keep a gRPC connection to the logging endpoint open indefinitely.

This results in a slow leak of tcp sockets (1) and memory (~200Kb) any time that a container using `--log-driver=gcplogs` is terminates.

Signed-off-by: Patrick Haas <patrickhaas@google.com>

Patrick Haas authored on 2020/10/01 06:52:22
Showing 1 changed files
... ...
@@ -54,6 +54,7 @@ func init() {
54 54
 }
55 55
 
56 56
 type gcplogs struct {
57
+	client    *logging.Client
57 58
 	logger    *logging.Logger
58 59
 	instance  *instanceInfo
59 60
 	container *containerInfo
... ...
@@ -170,6 +171,7 @@ func New(info logger.Info) (logger.Logger, error) {
170 170
 	}
171 171
 
172 172
 	l := &gcplogs{
173
+		client: c,
173 174
 		logger: lg,
174 175
 		container: &containerInfo{
175 176
 			Name:      info.ContainerName,
... ...
@@ -237,7 +239,7 @@ func (l *gcplogs) Log(m *logger.Message) error {
237 237
 
238 238
 func (l *gcplogs) Close() error {
239 239
 	l.logger.Flush()
240
-	return nil
240
+	return l.client.Close()
241 241
 }
242 242
 
243 243
 func (l *gcplogs) Name() string {