We are developping a Grails (2.2.1) application with mongodb, and during stress tests we have found that there is a domain class that keeps a lot of instances actived even before garbage collection is done.
We have used jmeter to make more than 5000 queries to server and jvisualvm to trace the memory.
In jvisualvm we can se how other domain classes grow in instances, but when GC is done, the intances are cleaned, but with this domain class always keeps instances.
We have used app-info plugin and notice that there is no keeping any info in session.
There is the code of the domain class:
class User {
ObjectId id
String nickName
String email
String image
String password
String passwordBis
String token
static transients = ["passwordBis"]
static constraints = {
image nullable:true, blank:true
nickName nullable:false,blank:false,maxSize:100
email nullable:false,blank:false,email:true/*,unique:"company"*/
password nullable:true, blank:true
}
}
And there is the controller's action withch causes the memory leak:
def doLogin(String privateKey, String id){
try {
siteService.findPrivateSite(privateKey)
User user = User.get(id)
if (!user){
render text:"User does not exist for the given id",status:404
} else {
String token = UUID.randomUUID().toString()
user.token = token
user.save()
render token
}
} catch (InvalidRequestException e){
render text:e.getMessage(),status:404
}
}
The memory leak is in user.save() Are we doing something wrong? Is it a bug?