mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
Fix #4802: Add mutex protection to cancelActiveQuery
This commit is contained in:
@@ -55,6 +55,8 @@ type InteractiveClient struct {
|
|||||||
// NOTE: should ONLY be called by cancelActiveQueryIfAny
|
// NOTE: should ONLY be called by cancelActiveQueryIfAny
|
||||||
cancelActiveQuery context.CancelFunc
|
cancelActiveQuery context.CancelFunc
|
||||||
cancelPrompt context.CancelFunc
|
cancelPrompt context.CancelFunc
|
||||||
|
// mutex to protect concurrent access to cancelActiveQuery
|
||||||
|
cancelMutex sync.Mutex
|
||||||
|
|
||||||
// channel used internally to pass the initialisation result
|
// channel used internally to pass the initialisation result
|
||||||
initResultChan chan *db_common.InitResult
|
initResultChan chan *db_common.InitResult
|
||||||
|
|||||||
@@ -18,11 +18,16 @@ func (c *InteractiveClient) createPromptContext(parentContext context.Context) c
|
|||||||
|
|
||||||
func (c *InteractiveClient) createQueryContext(ctx context.Context) context.Context {
|
func (c *InteractiveClient) createQueryContext(ctx context.Context) context.Context {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
c.cancelMutex.Lock()
|
||||||
c.cancelActiveQuery = cancel
|
c.cancelActiveQuery = cancel
|
||||||
|
c.cancelMutex.Unlock()
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *InteractiveClient) cancelActiveQueryIfAny() {
|
func (c *InteractiveClient) cancelActiveQueryIfAny() {
|
||||||
|
c.cancelMutex.Lock()
|
||||||
|
defer c.cancelMutex.Unlock()
|
||||||
|
|
||||||
if c.cancelActiveQuery != nil {
|
if c.cancelActiveQuery != nil {
|
||||||
log.Println("[INFO] cancelActiveQueryIfAny CALLING cancelActiveQuery")
|
log.Println("[INFO] cancelActiveQueryIfAny CALLING cancelActiveQuery")
|
||||||
c.cancelActiveQuery()
|
c.cancelActiveQuery()
|
||||||
|
|||||||
Reference in New Issue
Block a user