From 1f14c37014f42eabfd1bd71d889027160342b685 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 7 Jun 2022 14:43:51 +0100 Subject: [PATCH] Avoid deadlock after panic during newQueryData --- plugin/plugin.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index bf6cee40..5a1249ef 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -218,9 +218,7 @@ func (p *Plugin) Execute(req *proto.ExecuteRequest, stream proto.WrapperPlugin_E } // lock access to the newQueryData - otherwise plugin crashes were observed - p.concurrencyLock.Lock() - queryData := newQueryData(queryContext, table, stream, p.Connection, matrixItem, p.ConnectionManager, req.CallId) - p.concurrencyLock.Unlock() + queryData := p.newQueryData(req, stream, queryContext, table, matrixItem) logger.Trace("calling fetchItems", "table", table.Name, "matrixItem", queryData.Matrix, "limit", queryContext.Limit) @@ -285,6 +283,13 @@ func (p *Plugin) Execute(req *proto.ExecuteRequest, stream proto.WrapperPlugin_E return nil } +func (p *Plugin) newQueryData(req *proto.ExecuteRequest, stream proto.WrapperPlugin_ExecuteServer, queryContext *QueryContext, table *Table, matrixItem []map[string]interface{}) *QueryData { + p.concurrencyLock.Lock() + defer p.concurrencyLock.Unlock() + + return newQueryData(queryContext, table, stream, p.Connection, matrixItem, p.ConnectionManager, req.CallId) +} + // initialiseTables does 2 things: // 1) if a TableMapFunc factory function was provided by the plugin, call it // 2) call initialise on the table, plassing the plugin pointer which the table stores