From 8eda5dc6f0f7e05d7b3d62e1861af05b49a2574a Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 3 Feb 2021 17:31:17 +0300 Subject: Fix memory leak in the Worker.go --- plugins/server/plugin.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'plugins/server/plugin.go') diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go index 73ce71f7..18a3a316 100644 --- a/plugins/server/plugin.go +++ b/plugins/server/plugin.go @@ -140,7 +140,7 @@ func (server *Plugin) NewWorkerPool(ctx context.Context, opt pool.Config, env En } list := make([]events.Listener, 0, 1) - list = append(list, server.collectPoolLogs) + list = append(list, server.collectEvents) if len(listeners) != 0 { list = append(list, listeners...) } @@ -201,7 +201,7 @@ func (server *Plugin) setEnv(e Env) []string { return env } -func (server *Plugin) collectPoolLogs(event interface{}) { +func (server *Plugin) collectEvents(event interface{}) { if we, ok := event.(events.PoolEvent); ok { switch we.Event { case events.EventMaxMemory: @@ -235,6 +235,9 @@ func (server *Plugin) collectPoolLogs(event interface{}) { switch we.Event { case events.EventWorkerError: server.log.Error(we.Payload.(error).Error(), "pid", we.Worker.(worker.BaseProcess).Pid()) + case events.EventWorkerStderr: + // TODO unsafe byte to string convertation + server.log.Debug("worker stderr", "pid", we.Worker.(worker.BaseProcess).Pid(), "message", string(we.Payload.([]byte))) case events.EventWorkerLog: server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t"), "pid", we.Worker.(worker.BaseProcess).Pid()) } @@ -248,6 +251,9 @@ func (server *Plugin) collectWorkerLogs(event interface{}) { server.log.Error(we.Payload.(error).Error(), "pid", we.Worker.(worker.BaseProcess).Pid()) case events.EventWorkerLog: server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t"), "pid", we.Worker.(worker.BaseProcess).Pid()) + case events.EventWorkerStderr: + // TODO unsafe byte to string convertation + server.log.Debug("worker stderr", "pid", we.Worker.(worker.BaseProcess).Pid(), "message", string(we.Payload.([]byte))) } } } -- cgit v1.2.3 From f48602882cf3f7ab8f7bbecde0fc63ad3e0f29a6 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 3 Feb 2021 23:35:38 +0300 Subject: Tests update --- plugins/server/plugin.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'plugins/server/plugin.go') diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go index 18a3a316..99d93d19 100644 --- a/plugins/server/plugin.go +++ b/plugins/server/plugin.go @@ -234,12 +234,12 @@ func (server *Plugin) collectEvents(event interface{}) { if we, ok := event.(events.WorkerEvent); ok { switch we.Event { case events.EventWorkerError: - server.log.Error(we.Payload.(error).Error(), "pid", we.Worker.(worker.BaseProcess).Pid()) - case events.EventWorkerStderr: - // TODO unsafe byte to string convertation - server.log.Debug("worker stderr", "pid", we.Worker.(worker.BaseProcess).Pid(), "message", string(we.Payload.([]byte))) + server.log.Error(strings.TrimRight(we.Payload.(error).Error(), " \n\t")) case events.EventWorkerLog: - server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t"), "pid", we.Worker.(worker.BaseProcess).Pid()) + server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t")) + case events.EventWorkerStderr: + // TODO unsafe byte to string convert + server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t")) } } } @@ -248,12 +248,12 @@ func (server *Plugin) collectWorkerLogs(event interface{}) { if we, ok := event.(events.WorkerEvent); ok { switch we.Event { case events.EventWorkerError: - server.log.Error(we.Payload.(error).Error(), "pid", we.Worker.(worker.BaseProcess).Pid()) + server.log.Error(strings.TrimRight(we.Payload.(error).Error(), " \n\t")) case events.EventWorkerLog: - server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t"), "pid", we.Worker.(worker.BaseProcess).Pid()) + server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t")) case events.EventWorkerStderr: - // TODO unsafe byte to string convertation - server.log.Debug("worker stderr", "pid", we.Worker.(worker.BaseProcess).Pid(), "message", string(we.Payload.([]byte))) + // TODO unsafe byte to string convert + server.log.Debug(strings.TrimRight(string(we.Payload.([]byte)), " \n\t")) } } } -- cgit v1.2.3