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

[ELY-1096][JBEAP-10473]: Avoid possible race conditions incrementing the size of Rotating File Audit #795

Merged
merged 1 commit into from May 10, 2017

Conversation

yersan
Copy link
Contributor

@yersan yersan commented May 3, 2017

Although currentSize was declared as volatile, this field modifier is not enough to prevent race conditions. This patch uses an AtomicLong instead.

Jira issues:
https://issues.jboss.org/browse/ELY-1096
https://issues.jboss.org/browse/JBEAP-10473

@wildfly-ci
Copy link

Can one of the admins verify this patch?

@hkalina
Copy link

hkalina commented May 3, 2017

This should not be needed as preWrite() is called inside of synchronized block:
https://github.com/wildfly-security/wildfly-elytron/blob/master/src/main/java/org/wildfly/security/audit/FileAuditEndpoint.java#L108

@yersan
Copy link
Contributor Author

yersan commented May 4, 2017

Thanks for your review @honza889, yes you're right (I guess you wanted to say the write() method). I agree with you, I didn't check who was calling write(), now I think even the volatile modifier was unnecessary there.

@hkalina
Copy link

hkalina commented May 4, 2017

Actually both of them. You are true, feel free to remove the modifier.

@@ -50,7 +50,7 @@

private String nextSuffix;
private long nextRollover = Long.MAX_VALUE;
private volatile long currentSize = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a great solution I think, as it relies on synchronization by external parties. Unless the class as a whole does not have a thread-safety contract established, it's better to replace this with an AtomicLong which has an atomic getAndAdd method on it. Same for the other method below.

On the other hand if the class as a whole needs to update multiple fields atomically, then locking is necessary and should be done directly within the class IMO.

@@ -68,12 +68,18 @@
}
}

/**
* Notice the following, this method is not thread safe and should be called inside a synchronized block
*/
Copy link

@hkalina hkalina May 5, 2017

Choose a reason for hiding this comment

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

Similar javadoc would be better in superimplementation - in FileAuditEndpoint - to define contract as suggested by @dmlloyd. To define that any implementation of this methods are called in synchronization block surrounding one log message processing.

@yersan
Copy link
Contributor Author

yersan commented May 5, 2017

Thanks @honza889 , @dmlloyd for the help. I have updated the FileAuditEndpoint contract, maybe it makes more sense now.

@hkalina hkalina added the +1 HK label May 5, 2017
@darranl darranl added the +1 DAL label May 10, 2017
@darranl darranl merged commit ca8a481 into wildfly-security:master May 10, 2017
@yersan yersan deleted the bugs/ELY-1096 branch July 3, 2017 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants