Created
March 8, 2019 14:47
-
-
Save davbo/99a01ce5ffe482b55698e74a10f94af6 to your computer and use it in GitHub Desktop.
Example of deadlocking the Trillian memory storage backend with a uninitialized log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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