com.atlassian.confluence.pages.attachments.AttachmentDataStreamSizeMismatchException: Attachment data stream contains a different number of bytes to the declared size of the attachment. Expected: 495, actual: 6514

Atlassian JIRA | Don Willis [Atlassian] | 5 years ago
  1. 0

    When testing migration of attachments from the database to the filesystem I get about 400 of the stacktrace below. This is caused by a mismatch between the reported filesize in the attachment table and the actual length of the attachment. The current behaviour is to log the error and skip the attachment. However, I have checked some of the attachments and they are not actually broken. It is (at least sometimes) the attachment table that is incorrect. So really, Confluence should log a warning and migrate the data regardless. Note, I'm not sure how old this bug is, but since it's definitely older than 4.0 I've put "3.5" as the affects version. SQL to find a summary of the affected records: {code:sql} select count(*), attachments.filesize, avg(length(attachmentdata.data)), attachments.contenttype, attachments.attachment_comment, attachments.version from attachments, attachmentdata where attachments.attachmentid=attachmentdata.attachmentid and filesize != length(data) group by attachments.filesize, attachments.contenttype, attachments.attachment_comment, attachments.version {code} Sample stacktrace {noformat} 2011-10-19 14:57:02,346 ERROR [Long running task: Attachment data migration] [persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentCopier] copy Could not copy attachment: Attachment: Marketing Pyramid v.2 (542867488) jon -- referer: http://localhost:8080/confluence/admin/doeditattachmentstorage.action | url: /confluence/admin/doattachmentmigration.action | userName: dwillis.adm | action: doattachmentmigration com.atlassian.confluence.pages.attachments.AttachmentDataStreamSizeMismatchException: Attachment data stream contains a different number of bytes to the declared size of the attachment. Expected: 495, actual: 6514 at com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.writeStreamToFile(FileSystemAttachmentDataDao.java:241) at com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.saveDataForAttachment(FileSystemAttachmentDataDao.java:172) at com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.saveDataForAttachment(FileSystemAttachmentDataDao.java:132) at com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentCopier.copy(AbstractHibernateAttachmentDao.java:448) at com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentMigrator.migrate(AbstractHibernateAttachmentDao.java:503) at com.atlassian.confluence.util.longrunning.AttachmentMigrationLongRunningTask$1.doInTransactionWithoutResult(AttachmentMigrationLongRunningTask.java:71) at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128) at com.atlassian.confluence.util.longrunning.AttachmentMigrationLongRunningTask.runInternal(AttachmentMigrationLongRunningTask.java:66) at com.atlassian.confluence.util.longrunning.ConfluenceAbstractLongRunningTask.run(ConfluenceAbstractLongRunningTask.java:21) at com.atlassian.confluence.util.longrunning.ManagedTask.run(ManagedTask.java:35) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) {noformat}

    Atlassian JIRA | 5 years ago | Don Willis [Atlassian]
    com.atlassian.confluence.pages.attachments.AttachmentDataStreamSizeMismatchException: Attachment data stream contains a different number of bytes to the declared size of the attachment. Expected: 495, actual: 6514

    Root Cause Analysis

    1. com.atlassian.confluence.pages.attachments.AttachmentDataStreamSizeMismatchException

      Attachment data stream contains a different number of bytes to the declared size of the attachment. Expected: 495, actual: 6514

      at com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.writeStreamToFile()
    2. com.atlassian.confluence
      AttachmentMigrationLongRunningTask$1.doInTransactionWithoutResult
      1. com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.writeStreamToFile(FileSystemAttachmentDataDao.java:241)
      2. com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.saveDataForAttachment(FileSystemAttachmentDataDao.java:172)
      3. com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao.saveDataForAttachment(FileSystemAttachmentDataDao.java:132)
      4. com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentCopier.copy(AbstractHibernateAttachmentDao.java:448)
      5. com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentMigrator.migrate(AbstractHibernateAttachmentDao.java:503)
      6. com.atlassian.confluence.util.longrunning.AttachmentMigrationLongRunningTask$1.doInTransactionWithoutResult(AttachmentMigrationLongRunningTask.java:71)
      6 frames
    3. Spring Tx
      TransactionTemplate.execute
      1. org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
      2. org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
      2 frames
    4. com.atlassian.confluence
      ManagedTask.run
      1. com.atlassian.confluence.util.longrunning.AttachmentMigrationLongRunningTask.runInternal(AttachmentMigrationLongRunningTask.java:66)
      2. com.atlassian.confluence.util.longrunning.ConfluenceAbstractLongRunningTask.run(ConfluenceAbstractLongRunningTask.java:21)
      3. com.atlassian.confluence.util.longrunning.ManagedTask.run(ManagedTask.java:35)
      3 frames
    5. Java RT
      Thread.run
      1. java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      2. java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      3. java.util.concurrent.FutureTask.run(FutureTask.java:138)
      4. java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      5. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      6. java.lang.Thread.run(Thread.java:680)
      6 frames