Skip to content

Instantly share code, notes, and snippets.

@davbo
Created March 8, 2019 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davbo/99a01ce5ffe482b55698e74a10f94af6 to your computer and use it in GitHub Desktop.
Save davbo/99a01ce5ffe482b55698e74a10f94af6 to your computer and use it in GitHub Desktop.
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