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

Crash on BEFORE INSERT trigger using DECLARE variable #7720

Closed
0x4261756D opened this issue Apr 9, 2024 · 2 comments · Fixed by dolthub/go-mysql-server#2446
Closed

Crash on BEFORE INSERT trigger using DECLARE variable #7720

0x4261756D opened this issue Apr 9, 2024 · 2 comments · Fixed by dolthub/go-mysql-server#2446
Assignees
Labels
bug Something isn't working customer issue good repro Easily reproducible bugs panic

Comments

@0x4261756D
Copy link

When inserting into a table that has a before-insert trigger with a DECLARE variable in its body the dolt server crashes.

My trigger:

CREATE TRIGGER foo BEFORE INSERT ON PartNumber
BEGIN
  DECLARE newmax VARCHAR(255);
  SELECT CONCAT('A', MAX(CAST(SUBSTRING(UniqueID, 2) AS UNSIGNED)) + 1) INTO newmax FROM PartNumber;
  SET NEW.UniqueId = newmax;
END;

A simpler version that produces the same crash:

CREATE TRIGGER foo BEFORE INSERT ON PartNumber
BEGIN
  DECLARE newmax VARCHAR(255);
  SET newmax = 'FOO';
  SET NEW.UniqueID = newmax;
END;

Crashlog:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x16be072]

goroutine 1256 [running]:
github.com/dolthub/go-mysql-server/sql/expression.(*ProcedureReference).InitializeVariable(0x0, {0xc0024313e8, 0x6}, {0x37b8910, 0xc0023f2e40}, {0x0?, 0x0?})
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/expression/procedurereference.go:68 +0xf2
github.com/dolthub/go-mysql-server/sql/rowexec.(*declareVariablesIter).Next(0xc0007863a0, 0x1f755924c30?)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/rel_iters.go:736 +0xbe
github.com/dolthub/go-mysql-server/sql/rowexec.(*triggerBlockIter).Next(0xc000b23500, 0xc000a759a0)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/dml_iters.go:103 +0x202
github.com/dolthub/go-mysql-server/sql/rowexec.(*triggerIter).Next(0xc0023b4410, 0x0?)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/dml_iters.go:217 +0x30f
github.com/dolthub/go-mysql-server/sql/rowexec.(*insertIter).Next(0xc0025125b0, 0xc000d5b0e0)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/insert.go:63 +0x3e
github.com/dolthub/go-mysql-server/sql/plan.(*TableEditorIter).Next(0xc0023b4460, 0xc000d5b0e0)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/plan/table_editor.go:55 +0x72
github.com/dolthub/go-mysql-server/sql/rowexec.(*accumulatorIter).Next(0xc000523770, 0xc000d5b0e0)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/dml_iters.go:513 +0x1f7
github.com/dolthub/go-mysql-server/sql/rowexec.(*triggerRollbackIter).Next(0xc000107a70, 0xc000d5b0e0)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/dml_iters.go:37 +0x3d
github.com/dolthub/go-mysql-server/sql/rowexec.transactionCommittingIter.Next(...)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/rowexec/transaction_iters.go:78
github.com/dolthub/go-mysql-server/sql/plan.(*trackedRowIter).Next(0xc000b23440, 0xc00010f8c0?)
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/sql/plan/process.go:357 +0x24
github.com/dolthub/go-mysql-server/server.(*Handler).doQuery.func2()
	C:/Users/User/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.18.1-0.20240405190351-4baf7c65a6db/server/handler.go:425 +0x124
golang.org/x/sync/errgroup.(*Group).Go.func1()
	C:/Users/User/go/pkg/mod/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 186
	C:/Users/User/go/pkg/mod/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:75 +0x96

@jycor
Copy link
Contributor

jycor commented Apr 10, 2024

Hey @0x4261756D, thanks for reporting this issue!

Triggers are a tricky area for us, but we are looking into it.
For now, we have it so that triggers like this won't panic.

@jycor
Copy link
Contributor

jycor commented Apr 12, 2024

Hey @0x4261756D, the fix for this has been merged to dolt main.

DECLAREs should work just fine in triggers.
While fixing this issue, we discovered #7737 .
So, just don't call external stored procedures in your triggers, and it should be fine.

A release with the fix should be out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working customer issue good repro Easily reproducible bugs panic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants