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

Safer UnsafeBuffer.toString() and UnsafeBuffer.hashcode() #106

Closed
RichardWarburton opened this issue Sep 4, 2017 · 5 comments
Closed

Safer UnsafeBuffer.toString() and UnsafeBuffer.hashcode() #106

RichardWarburton opened this issue Sep 4, 2017 · 5 comments

Comments

@RichardWarburton
Copy link
Contributor

If an UnsafeBuffer is wrapping an underlying mappedbytebuffer and it gets unmapped/closed then operations like toString() and hashcode() cause a segfault, because they rely on the values of the mappedbytebuffer. I'm wondering if there's not a safer way of doing things? Or perhaps at least documenting: don't call toString() or hashcode() after you've been unmapped.

@mjpt777
Copy link
Contributor

mjpt777 commented Sep 4, 2017

It should be the case that you don't call anything, except possibly wrapping another buffer, after an unmap.

@RichardWarburton
Copy link
Contributor Author

So for context in this case I was logging when a buffer was being closed in order to discover which buffer wasn't being closed. I wouldn't expect to be able to do anything else to a buffer, but the behaviour of segfaulting the JVM on I called toString() was quite surprising.

@mjpt777
Copy link
Contributor

mjpt777 commented Sep 4, 2017

BTW there is no toString() method on UnsafeBuffer other than the one inherited from Object. There is an equals and hashCode. What was the issue with toString() you are seeing?

@RichardWarburton
Copy link
Contributor Author

Yeah, sorry I should have explained it better. UnsafeBuffer inherits the toString() method from Object, which then invokes hashcode() on itself, thus calling UnsafeBuffer.hashcode(). the hashcode() causes the segfault.

@mjpt777
Copy link
Contributor

mjpt777 commented Sep 4, 2017

That makes more sense. We should provide one that does a reasonable thing so debuggers don't cause a crash in that case.

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