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

StorageSubscription.Unsubscribe race #188

Open
ggwpez opened this issue Sep 16, 2021 · 3 comments
Open

StorageSubscription.Unsubscribe race #188

ggwpez opened this issue Sep 16, 2021 · 3 comments

Comments

@ggwpez
Copy link

ggwpez commented Sep 16, 2021

Hi there,

i am using gsrpc in a project and noticed that a race occurs when trying to unsubscribe from a StorageSubscription while a second one is running.
This is weird since i never spawned a go-routine myself.

Place the following test in main_test.go and execute go test -v -count=1 -race -run=TestClient_Subscribe .:

func TestClient_Subscribe(t *testing.T) {
	// Setup and chain connection
	api, err := gsrpc.NewSubstrateAPI(config.Default().RPCURL)
	require.NoError(t, err)
	meta, err := api.RPC.State.GetMetadataLatest()
	require.NoError(t, err)
	// Use "Time" if you run an older node version.
	key, err := types.CreateStorageKey(meta, "Timestamp", "Now")
	require.NoError(t, err)

	// Subscribe once
	sub1, err := api.RPC.State.SubscribeStorageRaw([]types.StorageKey{key})
	require.NoError(t, err)

	// Subscribe twice
	_, err = api.RPC.State.SubscribeStorageRaw([]types.StorageKey{key})
	require.NoError(t, err)

	// Unsubscribing produces a race!
	sub1.Unsubscribe()
}

Test output: race.txt.
The problem seems to occur between

chosen, recv, _ = reflect.Select(cases)
and
Any help with this would be much appreciated, thanks for your time 🙏

@NunoAlexandre
Copy link
Contributor

@ggwpez did you happen to resolve this issue?

@ggwpez
Copy link
Author

ggwpez commented Nov 22, 2021

@ggwpez did you happen to resolve this issue?

No, we just refrained from running the race tests in our project
I saw that this is old code copied from geth, maybe it could help to update it? I dont know.
Instead it could also use a fork as subrepo here, to keep track which files were changed from the geth code.
@NunoAlexandre

@cdamian
Copy link
Contributor

cdamian commented Dec 5, 2023

Will most likely create a geth fork and use that given another issue reported here - #362

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

3 participants