The immudb server crashes miserably when attempting to modify the same table more than once in the same transaction. It is understandable that modifying the same table in the same transaction might not be allowed, but a crash resulting from this is unforgivable.
Apparently, the problem only occurs in columns that are indexed.
Honestly, I expected immudb to be able to calculate the changes within a transaction and apply them accordingly. If that were not possible, at least it should give an error instead of causing the server to crash.
How to reproduce it
This bug is easily reproducible. To make it easier, I wrote some code here that makes the server crash 100% of the time:
package tools
import (
"context"
"os"
"strconv"
"testing"
immudb "github.com/codenotary/immudb/pkg/client"
"github.com/joho/godotenv"
)
// immuadmin 1.9.3
// Commit : 5487dd300655083ff68c4a72c2edb38ca84dd1bb
// Built at: Thu, 23 May 2024 10:08:05 UTC
// Static : true
// CREATE TABLE test_table (
// id INTEGER,
// name VARCHAR,
// age INTEGER,
// active BOOLEAN,
// salary FLOAT,
// created_at TIMESTAMP,
// data BLOB,
// notes VARCHAR,
// PRIMARY KEY (id)
// )
// INSERT INTO test_table (id, name, age, active, salary, created_at, data, notes) VALUES
// (1, 'Alice', 30, true, 1000.50, NOW(), x'010203', 'Note 1'),
// (2, 'Bob', 25, false, 2000.75, NOW(), x'040506', 'Note 2'),
// (3, 'Charlie', NULL, NULL, NULL, NULL, NULL, NULL)
// CREATE INDEX IF NOT EXISTS ON test_table(salary,created_at);
func TestImmudbCrash(t *testing.T) {
ctx := context.Background()
err := godotenv.Load("../.env")
if err != nil {
t.Fatalf("Error loading .env file: %v", err)
}
portAsInt, _ := strconv.Atoi(os.Getenv("IMMUDB_PORT"))
var opts = immudb.DefaultOptions().
WithAddress(os.Getenv("IMMUDB_HOST")).
WithPort(portAsInt)
var db = immudb.NewClient().WithOptions(opts)
err = db.OpenSession(
ctx,
[]byte(os.Getenv("IMMUDB_USER")),
[]byte(os.Getenv("IMMUDB_PWD")),
os.Getenv("IMMUDB_DB"),
)
if err != nil {
t.Fatalf("Error opening session: %v", err)
}
defer func() {
if err := db.CloseSession(ctx); err != nil {
t.Fatalf("Failed to close session: %v", err)
}
}()
var dbTx immudb.Tx
dbTx, err = db.NewTx(ctx)
if err != nil {
t.Fatalf("Error creating new transaction: %v", err)
}
err = dbTx.SQLExec(ctx, "UPDATE test_table SET salary = 1000.0 WHERE id = 1", nil)
if err != nil {
t.Fatalf("Error executing SQL statement: %v", err)
}
err = dbTx.SQLExec(ctx, "UPDATE test_table SET salary = 1001.0 WHERE id = 1", nil)
if err != nil {
t.Fatalf("Error executing SQL statement: %v", err)
}
_, err = dbTx.Commit(ctx)
if err != nil {
t.Fatalf("Error committing transaction: %v", err)
}
}
Environment
immuadmin 1.9.3
Commit : 5487dd300655083ff68c4a72c2edb38ca84dd1bb
Built at: Thu, 23 May 2024 10:08:05 UTC
Static : true
What happened
The immudb server crashes miserably when attempting to modify the same table more than once in the same transaction. It is understandable that modifying the same table in the same transaction might not be allowed, but a crash resulting from this is unforgivable.
Apparently, the problem only occurs in columns that are indexed.
What you expected to happen
Honestly, I expected immudb to be able to calculate the changes within a transaction and apply them accordingly. If that were not possible, at least it should give an error instead of causing the server to crash.
How to reproduce it
This bug is easily reproducible. To make it easier, I wrote some code here that makes the server crash 100% of the time:
Environment