turbot / steampipe

Zero-ETL, infinite possibilities. Live query APIs, code & more with SQL. No DB required.
https://steampipe.io
GNU Affero General Public License v3.0
6.84k stars 264 forks source link

Dashboard process occasionally crashes if a workspace resource has invalid SQL #2705

Closed MichaelBurgess closed 1 year ago

MichaelBurgess commented 1 year ago

Occasionally, whilst working on a dashboard in the HCL I've seen the below crash - the only pattern I can think is that I've either got an unterminated sql string, or the sql is not escaped correctly:

E.g.

node "node_1" {
  sql = "select 0 as id, 'node_1' as title
}

I've seen this happen in both 0.17.x and 0.18.x, but not been able to track down why really until now.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10042baa0]

goroutine 1297 [running]:
fmt.(*buffer).writeString(...)
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/print.go:82
fmt.(*fmt).padString(0x10000000a?, {0x0, 0x3a})
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/format.go:110 +0x224
fmt.(*fmt).fmtS(0x14000d076a0?, {0x0?, 0x7?})
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/format.go:359 +0x40
fmt.(*pp).fmtString(0x5?, {0x0?, 0x14009907908?}, 0x4350e0?)
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/print.go:477 +0xe4
fmt.(*pp).printArg(0x1400ff6a820, {0x101874ae0?, 0x14000d07730}, 0x73)
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/print.go:725 +0x234
fmt.(*pp).doPrintf(0x1400ff6a820, {0x10145466e, 0x14}, {0x14009907b38?, 0x2, 0x2})
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/print.go:1057 +0x21c
fmt.Sprintf({0x10145466e, 0x14}, {0x14009907b38, 0x2, 0x2})
    /opt/homebrew/Cellar/go/1.19.1/libexec/src/fmt/print.go:219 +0x4c
github.com/turbot/steampipe/pkg/db/db_common.getPreparedStatementCreateSql({0x101af6c00?, 0x14009f7c280?})
    /Users/mike/Code/github.com/turbot/steampipe/pkg/db/db_common/prepared_statements.go:79 +0x130
github.com/turbot/steampipe/pkg/db/db_common.GetPreparedStatementsSQL(0x10147ee7c?)
    /Users/mike/Code/github.com/turbot/steampipe/pkg/db/db_common/prepared_statements.go:61 +0x74
github.com/turbot/steampipe/pkg/db/db_common.CreatePreparedStatements({0x101ae7d00, 0x140019a7bf0}, 0x1?, 0x1?, 0x0)
    /Users/mike/Code/github.com/turbot/steampipe/pkg/db/db_common/prepared_statements.go:32 +0x8c
github.com/turbot/steampipe/pkg/workspace.EnsureSessionData({0x101ae7d00, 0x140019a7bf0}, 0x14004d5e4f0, 0x140065e7d10, 0xa0?)
    /Users/mike/Code/github.com/turbot/steampipe/pkg/workspace/session_data.go:32 +0x120
github.com/turbot/steampipe/pkg/initialisation.(*InitData).Init.func2({0x101ae7d00?, 0x140019a7bf0?}, 0x1018f0ba0?)
    /Users/mike/Code/github.com/turbot/steampipe/pkg/initialisation/init_data.go:120 +0x44
github.com/turbot/steampipe/pkg/db/db_client.NewDbClient.func1({0x101ae7d00, 0x140019a7bf0}, 0x140065eb8c0?)
    /Users/mike/Code/github.com/turbot/steampipe/pkg/db/db_client/db_client.go:63 +0x90
github.com/jackc/pgx/v4/pgxpool.ConnectConfig.func1({0x101ae6480?, 0x14003bd4200?})
    /Users/mike/go/pkg/mod/github.com/jackc/pgx/v4@v4.17.2/pgxpool/pool.go:238 +0x190
github.com/jackc/puddle.(*Pool).constructResourceValue(...)
    /Users/mike/go/pkg/mod/github.com/jackc/puddle@v1.3.0/pool.go:558
github.com/jackc/puddle.(*Pool).CreateResource(0x14007458e80, {0x101ae6480, 0x14003bd4200})
    /Users/mike/go/pkg/mod/github.com/jackc/puddle@v1.3.0/pool.go:479 +0x7c
github.com/jackc/pgx/v4/pgxpool.(*Pool).createIdleResources.func1()
    /Users/mike/go/pkg/mod/github.com/jackc/pgx/v4@v4.17.2/pgxpool/pool.go:508 +0x6c
created by github.com/jackc/pgx/v4/pgxpool.(*Pool).createIdleResources
    /Users/mike/go/pkg/mod/github.com/jackc/pgx/v4@v4.17.2/pgxpool/pool.go:506 +0x7c
MichaelBurgess commented 1 year ago

@kaidaguerre just had the same crash whilst adding a graph, whilst not editing any sql.

github-actions[bot] commented 1 year ago

'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.'

github-actions[bot] commented 1 year ago

'This issue was closed because it has been stalled for 90 days with no activity.'