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

Handle race condition between File.length() and FileChannel.size() #140

Merged
merged 3 commits into from
Apr 30, 2018

Conversation

epickrram
Copy link
Contributor

Observed in the wild:

java.lang.IndexOutOfBoundsException: index=0 length=4 capacity=0
        at org.agrona.concurrent.UnsafeBuffer.boundsCheck0(UnsafeBuffer.java:1340)
        at org.agrona.concurrent.UnsafeBuffer.getIntVolatile(UnsafeBuffer.java:523)
        at org.agrona.MarkFile.mapExistingMarkFile(MarkFile.java:382)
        at org.agrona.MarkFile.<init>(MarkFile.java:178)
        at io.aeron.cluster.ClusterMarkFile.<init>(ClusterMarkFile.java:117)

This seems to be caused by File.length() returning a value greater than zero, passing this test:

while (!markFile.exists() || markFile.length() <= 0)

but then causing a zero-length buffer to be mapped here:

mappedByteBuffer = channel.map(READ_WRITE, 0, channel.size());

This PR adds a wait for FileChannel.size() to return at least 4, the minimum required to read the version number. I've also added a test to ensure that a more meaningful error message would be thrown in the event of a timeout.

@mjpt777 mjpt777 merged commit ad9e254 into real-logic:master Apr 30, 2018
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

Successfully merging this pull request may close these issues.

None yet

2 participants