kefirfromperm / grails-asynchronous-mail

The Grails Asynchronous Mail plugin
http://grails.org/plugin/asynchronous-mail
21 stars 36 forks source link

After update from grails 2.4.5 to 3.1.14 errors in logs #66

Closed demon101 closed 7 years ago

demon101 commented 7 years ago

For some of mails after update from grails 2.4.5 to 3.1.14 errors in logs

grails.app.services.grails.plugin.asyncmail.AsynchronousMailProcessService - An exception was thrown when attempting to send a message with id

compile 'org.grails.plugins:asynchronous-mail:2.0.0.RC4'

Settings

asynchronous.mail.default.max.attempts.count=3
asynchronous.mail.messages.at.once=200
asynchronous.mail.send.immediately=true  // since 0.1.2
asynchronous.mail.disable=false    // since 0.7
asynchronous.mail.persistence.provider='hibernate4' // Possible values are 'hibernate', 'hibernate4', 'mongodb'
asynchronous.mail.gparsPoolSize=1
asynchronous.mail.newSessionOnImmediateSend=false

Stack trace:

org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Object of class [grails.plugin.asyncmail.AsynchronousMailMessage] with identifier [1108823]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [grails.plugin.asyncmail.AsynchronousMailMessage#1108823] at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:202) at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:614) at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:200) at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:140) at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:110) at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.performSave(AbstractHibernateGormInstanceApi.groovy:234) at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:154) at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151) at org.grails.datastore.gorm.GormEntity$Trait$Helper$save$14.call(Unknown Source) at grails.plugin.asyncmail.AsynchronousMailMessage.save(AsynchronousMailMessage.groovy) at grails.plugin.asyncmail.AsynchronousMailMessage.save(AsynchronousMailMessage.groovy) at org.grails.datastore.gorm.GormEntity$save$1.call(Unknown Source) at grails.plugin.asyncmail.AsynchronousMailPersistenceService.save(AsynchronousMailPersistenceService.groovy:12) at sun.reflect.GeneratedMethodAccessor1538.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at grails.plugin.asyncmail.AsynchronousMailProcessService.processEmailMessage(AsynchronousMailProcessService.groovy:54) at sun.reflect.GeneratedMethodAccessor1577.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.j

Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [grails.plugin.asyncmail.AsynchronousMailMessage#1108786] at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:2541) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3285) at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3525) at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:159) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258) at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.flushSession(AbstractHibernateGormInstanceApi.groovy:272) at sun.reflect.GeneratedMethodAccessor1479.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

purpleraven commented 7 years ago

sending mail code:

asyncMailService.sendMail {
                to email
                if (ccList){
                    cc ccList
                }
                subject subjectString
                html(view: "/mails/${viewName}", model: model)
            }

One more detail: before setting was

asynchronous.mail.persistence.provider='hibernate'

At result, mail marked as SENT with one attempts

purpleraven commented 7 years ago

Strange, by the code, it fails during deleting of sent mail. But where is no option asynchronous.mail.clear.after.sent = true And in DB all async_mail_mess rows has mark_delete = false.

demon101 commented 7 years ago

For some message id (for example 1111830) I see this error 6 times. But attempts count for the message - 1

kefirfromperm commented 7 years ago

Which RDBMS do you use? Which transaction isolation level?

demon101 commented 7 years ago

defaultTransactionIsolation: 2 # = java.sql.Connection.TRANSACTION_READ_COMMITTED postgresql:9.4

kefirfromperm commented 7 years ago

Fixed 2.0.0.RC5