Skip to content

Instantly share code, notes, and snippets.

@davbo davbo/main.go
Created Mar 8, 2019

Embed
What would you like to do?
Example of deadlocking the Trillian memory storage backend with a uninitialized log
package main
import (
"context"
"fmt"
"github.com/google/trillian/util/clock"
"github.com/google/trillian"
"github.com/google/trillian/server"
"github.com/google/trillian/storage"
"github.com/google/trillian/extension"
"github.com/google/trillian/merkle/rfc6962"
stestonly "github.com/google/trillian/storage/testonly"
)
func main() {
th := rfc6962.DefaultHasher
var tree *trillian.Tree
ctx := context.Background()
sp, _ := server.NewStorageProvider("memory", nil)
sp.AdminStorage().ReadWriteTransaction(ctx, func(ctx context.Context, tx storage.AdminTX) error {
tree, _ = tx.CreateTree(ctx, stestonly.LogTree)
tx.Commit()
return nil
})
registry := extension.Registry{
AdminStorage: sp.AdminStorage(),
LogStorage: sp.LogStorage(),
}
timeSource := clock.System
logServer := *server.NewTrillianLogRPCServer(registry, timeSource)
data := []byte(`foo`)
hash, _:= th.HashLeaf(data)
leaf := &trillian.LogLeaf{
MerkleLeafHash: hash,
LeafValue: data,
LeafIdentityHash: hash,
}
req := &trillian.QueueLeavesRequest{LogId: tree.TreeId, Leaves: []*trillian.LogLeaf{leaf}}
logServer.QueueLeaves(ctx, req) // tx isn't closed
logServer.QueueLeaves(ctx, req) // blocks on acquiring lock
fmt.Print("Deadlocked?")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.