Uploaded image for project: 'Jira Platform Cloud'
  1. Jira Platform Cloud
  2. JRACLOUD-65470

Mail handler should set a max size on the email it handles

XMLWordPrintable

      The Mail handler contains logic to ensure it does not create issues that exceed a specified size. This is in order to defend against out of memory errors when viewing an issue, however it still loads the email content into memory before making such checks.

      If the mail is large enough JIRA will run out of memory and the email will not get handled, and the process will repeat the next time the mail fetcher runs.

      A stacktrace showing the problem in flight is given below:

       Stacks at the moment of snapshot capture Threads shown: 1 of 118
      
      
       Caesium-1-3 tid=131 [RUNNABLE] [DAEMON] <--- OutOfMemoryError happened in this thread
      java.lang.OutOfMemoryError.<init>() OutOfMemoryError.java:48
      java.lang.StringBuilder.append(String) StringBuilder.java:136
      com.atlassian.jira.plugins.mail.handlers.CreateIssueHandler.recordFromAddressForAnon(ApplicationUser, Message, String) CreateIssueHandler.java:489
      com.atlassian.jira.plugins.mail.handlers.CreateIssueHandler.getDescription(ApplicationUser, Message) CreateIssueHandler.java:470
      com.atlassian.jira.plugins.mail.handlers.CreateIssueHandler.handleMessage(Message, MessageHandlerContext) CreateIssueHandler.java:215
      com.atlassian.jira.plugins.mail.handlers.CreateOrCommentHandler.handleMessage(Message, MessageHandlerContext) CreateOrCommentHandler.java:133
      com.atlassian.jira.service.services.mail.MailFetcherService$1.process(Message, MessageHandlerContext) MailFetcherService.java:381
      com.atlassian.jira.service.services.mail.MailFetcherService$MessageProviderImpl.getAndProcessMail(MailFetcherService$MessageProvider$SingleMessageProcessor, MailServer, MessageHandlerContext) MailFetcherService.java:260
      com.atlassian.jira.service.services.mail.MailFetcherService.runImpl(MessageHandlerContext) MailFetcherService.java:371
      com.atlassian.jira.service.services.file.AbstractMessageHandlingService.run() AbstractMessageHandlingService.java:229
      com.atlassian.jira.service.JiraServiceContainerImpl.run() JiraServiceContainerImpl.java:61
      com.atlassian.jira.service.ServiceRunner.runService(JiraServiceContainer) ServiceRunner.java:62
      com.atlassian.jira.service.ServiceRunner.runServiceId(Long) ServiceRunner.java:44
      com.atlassian.jira.service.ServiceRunner.runJob(JobRunnerRequest) ServiceRunner.java:32
      com.atlassian.scheduler.core.JobLauncher.runJob() JobLauncher.java:153
      com.atlassian.scheduler.core.JobLauncher.launchAndBuildResponse() JobLauncher.java:118
      com.atlassian.scheduler.core.JobLauncher.launch() JobLauncher.java:97
      com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.launchJob(RunMode, Date, JobDetails) CaesiumSchedulerService.java:453
      com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJob(QueuedJob) CaesiumSchedulerService.java:447
      com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeQueuedJob(QueuedJob) CaesiumSchedulerService.java:394
      com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService$1.consume(QueuedJob) CaesiumSchedulerService.java:279
      com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService$1.consume(Object) CaesiumSchedulerService.java:275
      com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeJob(QueuedJob) SchedulerQueueWorker.java:78
      com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeNextJob() SchedulerQueueWorker.java:70
      com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.run() SchedulerQueueWorker.java:40
      java.lang.Thread.run() Thread.java:745
      

      There's a couple of things we could better here - we render the message body to a string, and then we use naive string concatenation to add to it. We should check the size of the message before reading it all, and use a buffer to hold the content until we're done manipulating it.

              mtokar Michael Tokar
              rcordova Cordo
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: