Skip to content

Commit

Permalink
Avoid deadlock after panic during newQueryData. Closes #332
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre authored Jun 10, 2022
1 parent f6db53e commit 47924aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 47924aa

Please sign in to comment.