Skip to content

Commit 8099e0b

Browse files
committed
dashboard/app: retry transactions in emulator on error
Datastore emulator specific error makes our tests flaky. This change will likely solve the problem.
1 parent 0199f9a commit 8099e0b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

dashboard/app/entities_datastore.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/google/syzkaller/dashboard/dashapi"
1515
"github.com/google/syzkaller/pkg/hash"
1616
"github.com/google/syzkaller/pkg/subsystem"
17+
"google.golang.org/appengine/v2"
1718
db "google.golang.org/appengine/v2/datastore"
1819
)
1920

@@ -1199,5 +1200,21 @@ func runInTransaction(ctx context.Context, tx txFunc, opts *db.TransactionOption
11991200
if opts.Attempts == 0 {
12001201
opts.Attempts = 10
12011202
}
1202-
return db.RunInTransaction(ctx, tx, opts)
1203+
const maxDevAppServerRetries = 100
1204+
var err error
1205+
for i := 0; i < maxDevAppServerRetries; i++ {
1206+
err = db.RunInTransaction(ctx, tx, opts)
1207+
if err != nil && appengine.IsDevAppServer() {
1208+
errStr := err.Error()
1209+
// This is a hack to work around the fact that the dev app server
1210+
// returns the emulator specific error under pressure:
1211+
// "API error 1 (datastore_v3: BAD_REQUEST): Transaction(<handle: XXX, app: "dev~testapp-12", >) not found"
1212+
if strings.Contains(errStr, "Transaction") && strings.Contains(errStr, "not found") {
1213+
time.Sleep(10 * time.Millisecond)
1214+
continue
1215+
}
1216+
}
1217+
return err
1218+
}
1219+
return fmt.Errorf("failed after %v dev server retries: %w", maxDevAppServerRetries, err)
12031220
}

0 commit comments

Comments
 (0)