Skip to content

Commit 064f21d

Browse files
server-write-panic
Summary: - Add mutex protection for handler context clone.
1 parent 783e018 commit 064f21d

File tree

10 files changed

+20
-22
lines changed

10 files changed

+20
-22
lines changed

internal/stackql/cmd/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ stackql exec -i iqlscripts/create-disk.iql --credentialsfilepath /mnt/c/tmp/stac
7878
}
7979
inputBundle, err := entryutil.BuildInputBundle(runtimeCtx)
8080
iqlerror.PrintErrorAndExitOneIfError(err)
81-
handlerCtx, err := entryutil.BuildHandlerContext(runtimeCtx, rdr, queryCache, inputBundle)
81+
handlerCtx, err := entryutil.BuildHandlerContext(runtimeCtx, rdr, queryCache, inputBundle, true)
8282
iqlerror.PrintErrorAndExitOneIfError(err)
8383
iqlerror.PrintErrorAndExitOneIfNil(handlerCtx, "Handler context error")
8484
cr := newCommandRunner()

internal/stackql/cmd/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var registryCmd = &cobra.Command{
8787

8888
inputBundle, err := entryutil.BuildInputBundle(runtimeCtx)
8989
iqlerror.PrintErrorAndExitOneIfError(err)
90-
handlerCtx, err := entryutil.BuildHandlerContext(runtimeCtx, rdr, queryCache, inputBundle)
90+
handlerCtx, err := entryutil.BuildHandlerContext(runtimeCtx, rdr, queryCache, inputBundle, true)
9191
iqlerror.PrintErrorAndExitOneIfError(err)
9292
iqlerror.PrintErrorAndExitOneIfNil(handlerCtx, "Handler context error")
9393
cr := newCommandRunner()

internal/stackql/cmd/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var shellCmd = &cobra.Command{
126126
inputBundle, err := entryutil.BuildInputBundle(runtimeCtx)
127127
iqlerror.PrintErrorAndExitOneIfError(err)
128128

129-
handlerCtx, handlerrErr := handler.GetHandlerCtx("", runtimeCtx, queryCache, inputBundle)
129+
handlerCtx, handlerrErr := handler.NewHandlerCtx("", runtimeCtx, queryCache, inputBundle)
130130
if handlerrErr != nil {
131131
fmt.Fprintln( //nolint:gosimple // legacy
132132
outErrFile,

internal/stackql/cmd/srv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var srvCmd = &cobra.Command{
4343
iqlerror.PrintErrorAndExitOneIfError(flagErr)
4444
inputBundle, err := entryutil.BuildInputBundle(runtimeCtx)
4545
iqlerror.PrintErrorAndExitOneIfError(err)
46-
handlerCtx, err := entryutil.BuildHandlerContextNoPreProcess(runtimeCtx, queryCache, inputBundle)
46+
handlerCtx, err := entryutil.BuildHandlerContext(runtimeCtx, nil, queryCache, inputBundle, false)
4747
iqlerror.PrintErrorAndExitOneIfError(err)
4848
sbe := driver.NewStackQLDriverFactory(handlerCtx)
4949
server, err := psqlwire.MakeWireServer(sbe, runtimeCtx)

internal/stackql/driver/driver_bench_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func BenchmarkSelectGoogleComputeInstanceDriver(b *testing.B) {
4747
stringQuery := `select count(1) as inst_count from google.compute.instances where zone = 'australia-southeast1-b' AND /* */ project = 'testing-project';`
4848

4949
runtimeCtx.LogLevelStr = "fatal"
50-
handlerCtx, err := handler.GetHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
50+
handlerCtx, err := handler.NewHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
5151
handlerCtx.SetOutfile(io.Discard)
5252
handlerCtx.SetOutErrFile(io.Discard)
5353

@@ -97,7 +97,7 @@ func BenchmarkParallelProjectSelectGoogleComputeInstanceDriver(b *testing.B) {
9797

9898
stringQuery := `select count(1) as inst_count from google.compute.instances where zone = 'australia-southeast1-b' AND /* */ project in ('testing-project', 'testing-project-two');`
9999

100-
handlerCtx, err := handler.GetHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
100+
handlerCtx, err := handler.NewHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
101101
handlerCtx.SetOutfile(io.Discard)
102102
handlerCtx.SetOutErrFile(io.Discard)
103103

@@ -307,7 +307,7 @@ func BenchmarkHighlyParallelProjectSelectGoogleComputeInstanceDriver(b *testing.
307307
)
308308
;`
309309

310-
handlerCtx, err := handler.GetHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
310+
handlerCtx, err := handler.NewHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
311311
handlerCtx.SetOutfile(io.Discard)
312312
handlerCtx.SetOutErrFile(io.Discard)
313313

@@ -517,7 +517,7 @@ func BenchmarkLoosenedHighlyParallelProjectSelectGoogleComputeInstanceDriver(b *
517517
)
518518
;`
519519

520-
handlerCtx, err := handler.GetHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
520+
handlerCtx, err := handler.NewHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
521521
handlerCtx.SetOutfile(io.Discard)
522522
handlerCtx.SetOutErrFile(io.Discard)
523523

@@ -727,7 +727,7 @@ func BenchmarkUnlimitedHighlyParallelProjectSelectGoogleComputeInstanceDriver(b
727727
)
728728
;`
729729

730-
handlerCtx, err := handler.GetHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
730+
handlerCtx, err := handler.NewHandlerCtx(stringQuery, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
731731
handlerCtx.SetOutfile(io.Discard)
732732
handlerCtx.SetOutErrFile(io.Discard)
733733

internal/stackql/driver/driver_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestSimpleSelectGoogleComputeInstanceDriver(t *testing.T) {
5050
t.Fatalf("Test failed: %v", err)
5151
}
5252

53-
handlerCtx, err := handler.GetHandlerCtx(testobjects.SimpleSelectGoogleComputeInstance, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
53+
handlerCtx, err := handler.NewHandlerCtx(testobjects.SimpleSelectGoogleComputeInstance, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
5454
handlerCtx.SetOutfile(os.Stdout)
5555
handlerCtx.SetOutErrFile(os.Stderr)
5656

internal/stackql/driver/okta_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestSelectOktaApplicationAppsDriver(t *testing.T) {
6060
t.Fatalf("Test failed: %v", err)
6161
}
6262

63-
handlerCtx, err := handler.GetHandlerCtx(testobjects.SimpleSelectOktaApplicationApps, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
63+
handlerCtx, err := handler.NewHandlerCtx(testobjects.SimpleSelectOktaApplicationApps, *runtimeCtx, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)
6464
handlerCtx.SetOutfile(os.Stdout)
6565
handlerCtx.SetOutErrFile(os.Stderr)
6666

internal/stackql/entryutil/entryutil.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,12 @@ func BuildHandlerContext(
243243
rdr io.Reader,
244244
lruCache *lrucache.LRUCache,
245245
inputBundle bundle.Bundle,
246+
isPreprocess bool,
246247
) (handler.HandlerContext, error) {
248+
if !isPreprocess {
249+
return handler.NewHandlerCtx("", runtimeCtx, lruCache, inputBundle)
250+
}
247251
bb, err := assemblePreprocessor(runtimeCtx, rdr)
248252
iqlerror.PrintErrorAndExitOneIfError(err)
249-
return handler.GetHandlerCtx(strings.TrimSpace(string(bb)), runtimeCtx, lruCache, inputBundle)
250-
}
251-
252-
func BuildHandlerContextNoPreProcess(
253-
runtimeCtx dto.RuntimeCtx,
254-
lruCache *lrucache.LRUCache,
255-
inputBundle bundle.Bundle,
256-
) (handler.HandlerContext, error) {
257-
return handler.GetHandlerCtx("", runtimeCtx, lruCache, inputBundle)
253+
return handler.NewHandlerCtx(strings.TrimSpace(string(bb)), runtimeCtx, lruCache, inputBundle)
258254
}

internal/stackql/handler/handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ func getRegistry(runtimeCtx dto.RuntimeCtx) (anysdk.RegistryAPI, error) {
474474
}
475475

476476
func (hc *standardHandlerContext) Clone() HandlerContext {
477+
hc.sessionCtxMutex.Lock()
478+
defer hc.sessionCtxMutex.Unlock()
477479
rv := standardHandlerContext{
478480
authMapMutex: hc.authMapMutex,
479481
sessionCtxMutex: hc.sessionCtxMutex,
@@ -507,7 +509,7 @@ func (hc *standardHandlerContext) Clone() HandlerContext {
507509
return &rv
508510
}
509511

510-
func GetHandlerCtx(
512+
func NewHandlerCtx(
511513
cmdString string,
512514
runtimeCtx dto.RuntimeCtx,
513515
lruCache *lrucache.LRUCache,

internal/stackql/querysubmit/querysubmit_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestSimpleSelectGoogleComputeInstanceQuerySubmit(t *testing.T) {
4444
t.Fatalf("Test failed: %v", err)
4545
}
4646

47-
handlerCtx, err := handler.GetHandlerCtx(
47+
handlerCtx, err := handler.NewHandlerCtx(
4848
testobjects.SimpleSelectGoogleComputeInstance,
4949
*runtimeCtx,
5050
lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle)

0 commit comments

Comments
 (0)