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

Add finalizer to zstd. #3306

Merged
merged 1 commit into from
Feb 26, 2021
Merged

Add finalizer to zstd. #3306

merged 1 commit into from
Feb 26, 2021

Conversation

cyriltovena
Copy link
Contributor

Fixes #3305

Signed-off-by: Cyril Tovena cyril.tovena@gmail.com

Fixes grafana#3305

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Copy link
Collaborator

@kavirajk kavirajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to lock the behaviour via test somehow!

@cyriltovena
Copy link
Contributor Author

Would be nice to lock the behaviour via test somehow!

Yes I didn't how, you have an idea ?

@kavirajk
Copy link
Collaborator

kavirajk commented Feb 9, 2021

Yes I didn't how, you have an idea ?

Neither do I :P

Quickly checked the runtime package and found this

https://github.com/golang/go/blob/master/src/runtime/mfinal_test.go#L47-L71. Looks like we can trigger it via runtime.GC(). may be something similar we can do?

@cyriltovena
Copy link
Contributor Author

yeah I can trigger it for sure but how can I verify it was triggered :)

@kavirajk
Copy link
Collaborator

kavirajk commented Feb 10, 2021

how can I verify it was triggered :)

I'm thinking something like this

func (z *zfsReader) Close() {
	z.ch <- struct{}{}
}

// do something with the reader

<-done
runtime.GC()
select {
	case <-z.ch:
	case <-time.After(time.Second * 4):
		t.Errorf("finalizer didn't run")
	}
}

@owen-d
Copy link
Member

owen-d commented Feb 25, 2021

@kavirajk has a nice test suggestion to add :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zstd Reader not properly closed
4 participants