Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/catalog: v20.2.9: nil txn or mutex when resolving type #64975

Closed
cockroach-teamcity opened this issue May 11, 2021 · 1 comment · Fixed by #65108
Closed

sql/catalog: v20.2.9: nil txn or mutex when resolving type #64975

cockroach-teamcity opened this issue May 11, 2021 · 1 comment · Fixed by #65108
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report.

Comments

@cockroach-teamcity
Copy link
Member

This issue was autofiled by Sentry. It represents a crash or reported error on a live cluster with telemetry enabled.

Sentry link: https://sentry.io/organizations/cockroach-labs/issues/2392749777/?referrer=webhooks_plugin

Panic message:

conn_executor.go:506: runtime error: invalid memory address or nil pointer dereference
--
runtime.errorString
conn_executor.go:506: *withstack.withStack (top exception)
*safedetails.withSafeDetails: while executing: SELECT ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., . FROM _ AS _ WHERE ((((. = $1) AND ((($2 = ) AND (._ IS DISTINCT FROM )) OR (._ = ANY ($3)))) AND (. = $4)) AND (. = $5)) AND (. = ANY ($6)) (1)
conn_executor.go:506: *withstack.withStack (2)
(check the extra data payloads)

Stacktrace (expand for inline code snippets):

r := recover()
h.ex.closeWrapper(ctx, r)
}()
in pkg/sql.(*Server).ServeConn.func1
/usr/local/go/src/runtime/panic.go#L678-L680 in runtime.gopanic
/usr/local/go/src/runtime/panic.go#L198-L200 in runtime.panicmem
/usr/local/go/src/runtime/signal_unix.go#L393-L395 in runtime.sigpanic
/usr/local/go/src/sync/mutex.go#L73-L75 in sync.(*Mutex).Lock

cockroach/pkg/kv/txn.go

Lines 284 to 286 in c9d5466

func (txn *Txn) ReadTimestamp() hlc.Timestamp {
txn.mu.Lock()
defer txn.mu.Unlock()
in pkg/kv.(*Txn).ReadTimestamp
readTimestamp := txn.ReadTimestamp()
desc, expiration, err := tc.leaseMgr.Acquire(ctx, readTimestamp, id)
in pkg/sql/catalog/descs.(*Collection).getDescriptorVersionByID
) (*typedesc.Immutable, error) {
desc, err := tc.getDescriptorVersionByID(ctx, txn, typeID, flags.CommonLookupFlags, true /* setTxnDeadline */)
if err != nil {
in pkg/sql/catalog/descs.(*Collection).GetTypeVersionByID
) (tree.TypeName, catalog.TypeDescriptor, error) {
desc, err := p.Descriptors().GetTypeVersionByID(ctx, p.txn, id, tree.ObjectLookupFlagsWithRequired())
if err != nil {
in pkg/sql.(*planner).GetTypeDescriptor
func (p *planner) ResolveTypeByOID(ctx context.Context, oid oid.Oid) (*types.T, error) {
name, desc, err := p.GetTypeDescriptor(ctx, typedesc.UserDefinedTypeOIDToID(oid))
if err != nil {
in pkg/sql.(*planner).ResolveTypeByOID
var err error
parseCmd.TypeHints[i], err = ex.planner.ResolveTypeByOID(ctx, parseCmd.RawTypeHints[i])
if err != nil {
in pkg/sql.(*connExecutor).execPrepare
stmtCtx := withStatement(ctx, ex.curStmt)
ev, payload = ex.execPrepare(stmtCtx, tcmd)
case DescribeStmt:
in pkg/sql.(*connExecutor).execCmd
var err error
if err = ex.execCmd(ex.Ctx()); err != nil {
if errors.IsAny(err, io.EOF, errDrainingComplete) {
in pkg/sql.(*connExecutor).run
}()
return h.ex.run(ctx, s.pool, reserved, cancel)
}
in pkg/sql.(*Server).ServeConn
reservedOwned = false // We're about to pass ownership away.
retErr = sqlServer.ServeConn(ctx, connHandler, reserved, cancelConn)
}()
in pkg/sql/pgwire.(*conn).processCommandsAsync.func1
/usr/local/go/src/runtime/asm_amd64.s#L1356-L1358 in runtime.goexit

pkg/sql/conn_executor.go in pkg/sql.(*Server).ServeConn.func1 at line 506
/usr/local/go/src/runtime/panic.go in runtime.gopanic at line 679
/usr/local/go/src/runtime/panic.go in runtime.panicmem at line 199
/usr/local/go/src/runtime/signal_unix.go in runtime.sigpanic at line 394
/usr/local/go/src/sync/mutex.go in sync.(*Mutex).Lock at line 74
pkg/kv/txn.go in pkg/kv.(*Txn).ReadTimestamp at line 285
pkg/sql/catalog/descs/collection.go in pkg/sql/catalog/descs.(*Collection).getDescriptorVersionByID at line 950
pkg/sql/catalog/descs/collection.go in pkg/sql/catalog/descs.(*Collection).GetTypeVersionByID at line 1406
pkg/sql/resolver.go in pkg/sql.(*planner).GetTypeDescriptor at line 260
pkg/sql/resolver.go in pkg/sql.(*planner).ResolveTypeByOID at line 314
pkg/sql/conn_executor_prepare.go in pkg/sql.(*connExecutor).execPrepare at line 68
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCmd at line 1551
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).run at line 1391
pkg/sql/conn_executor.go in pkg/sql.(*Server).ServeConn at line 508
pkg/sql/pgwire/conn.go in pkg/sql/pgwire.(*conn).processCommandsAsync.func1 at line 626
/usr/local/go/src/runtime/asm_amd64.s in runtime.goexit at line 1357
Tag Value
Cockroach Release v20.2.9
Cockroach SHA: c9d5466
Platform linux amd64
Distribution CCL
Environment v20.2.9
Command start-single-node
Go Version ``
# of CPUs
# of Goroutines
@cockroach-teamcity cockroach-teamcity added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report. labels May 11, 2021
@yuzefovich yuzefovich changed the title sentry: conn_executor.go:506: runtime error: invalid memory address or nil pointer dereference -- runtime.errorString conn_executor.go:506: *withstack.withStack (top exception) *safedetails.withSafeDetails: while executing: SELECT _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._, _._ FROM _ AS _ WHERE ((((_._ = $1) AND ((($2 = _) AND (_._ IS DISTINCT FROM _)) OR (_._ = ANY ($3)))) AND (_._ = $4)) AND (_._ = $5)) AND (_._ = ANY ($6)) (1) conn_executor.go:506: *withstack.withStack (2) (check the extra data payloads) sql/catalog: v20.2.9: nil txn or mutex when resolving type May 11, 2021
@ajwerner
Copy link
Contributor

The root cause here is #64140. I'm going to close this as duplicating that issue. @fqazi noted that just a week ago in #64140 (comment).

craig bot pushed a commit that referenced this issue May 13, 2021
65083: kvserver: speed up TestRollbackSyncRangedIntentResolution r=tbg a=erikgrinaker

Release note: None

65103: schemaexpr: remove expr_filter.go r=mgartner a=mgartner

This commit removes the `pkg/sql/catalog/schemaexpr/expr_filter.go`
file. The `schemaexpr` package is intended to contain logic for dealing
with expressions defined in a schema, such as check constraints,
computed columns, and partial index predicates. The two exported
functions in the file, `RemapIVarsInTypedExpr` and `RunFilter` did not
fit this theme. They have been moved elsewhere.

Release note: None

65108: sql: minor fixes to fix panics related to type resolution and bad planner usage r=otan a=ajwerner

See individual commits. The first commit matters but does not leave one with a good feeling. The second one is more copacetic.

Relates to #64140. 

Fixes #64975.

Release note (bug fix): Fixed a bug which could cause a panic when
running a EXECUTE of a previously PREPARE'd statement with a REGCLASS,
REGTYPE parameter or a user-defined type argument after running BEGIN
AS OF SYSTEM TIME with an invalid timestamp.

Release note (bug fix): Fixed a bug which could cause a panic when issuing
a query referencing a user-defined type as a placeholder as the first operation
on a new connection.

65130: cli/flags.go: fix typo in comment r=rauchenstein a=knz

Thanks to @stevendanna for spotting this.

Co-authored-by: Erik Grinaker <grinaker@cockroachlabs.com>
Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
Co-authored-by: Andrew Werner <awerner32@gmail.com>
Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
@craig craig bot closed this as completed in a8a6d85 May 13, 2021
@craig craig bot closed this as completed in #65108 May 13, 2021
ajwerner added a commit to ajwerner/cockroach that referenced this issue May 13, 2021
Before this change we'd resolve user-defined types into placeholder hints
using a planner which may not be in a valid state. This could result in
a nil-pointer panic.

I don't actually know how to trigger this from a driver but there's evidence
that it's possible. It's easy enough to hit using SQL if the previous commit
were not here.

Fixes cockroachdb#64975

Release note (bug fix): Fixed a bug which could cause a panic when issuing
a query referencing a user-defined type as a placeholder.
ajwerner added a commit to ajwerner/cockroach that referenced this issue May 14, 2021
Before this change we'd resolve user-defined types into placeholder hints
using a planner which may not be in a valid state. This could result in
a nil-pointer panic.

I don't actually know how to trigger this from a driver but there's evidence
that it's possible. It's easy enough to hit using SQL if the previous commit
were not here.

Fixes cockroachdb#64975

Release note (bug fix): Fixed a bug which could cause a panic when issuing
a query referencing a user-defined type as a placeholder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants