Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock with connection.BlockFetch().Client.GetBlock #774

Open
igorcrevar opened this issue Oct 29, 2024 · 0 comments
Open

Deadlock with connection.BlockFetch().Client.GetBlock #774

igorcrevar opened this issue Oct 29, 2024 · 0 comments
Assignees

Comments

@igorcrevar
Copy link
Contributor

If connection.BlockFetch().Client.GetBlock is executed on a closed connection, the next call will block indefinitely. I believe the issue is caused by a mutex that is not being unlocked. See the code below for reproduction:

func bugTest() error {
	connection, err := ouroboros.NewConnection(
		ouroboros.WithNetworkMagic(uint32(1)),
		ouroboros.WithNodeToNode(true),
	)
	if err != nil {
		return err
	}

	// dial some known node -> connect to node
	if err := connection.Dial("tcp", "preprod-node.play.dev.cardano.org:3001"); err != nil {
		return err
	}

	blockHash, err := hex.DecodeString("f7e99e7d597ef0b49ac4b442addb208b09ef928ee729487bc2d0a4e65dd11a66")
	if err != nil {
		return err
	}
        // some point that exists on testnet
	bp := common.Point{
		Slot: 74526873,
		Hash: blockHash,
	}

	b, err := connection.BlockFetch().Client.GetBlock(bp) // first call will pass
	if err != nil {
		return err
	}

	fmt.Println(b.SlotNumber(), b.Hash(), b.Transactions()) // will print some data

	connection.Close()

	_, err1 := connection.BlockFetch().Client.GetBlock(bp) // will retrieve error
	fmt.Println(err1) // this will print error "protocol is shutting down"

	_, err2 := connection.BlockFetch().Client.GetBlock(bp) // this will block
	fmt.Println(err2)

	return errors.Join(err1, err2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants