# Issue with deleting incoming dicoms when MaximumStorageSize is reached

**URL:** https://discourse.orthanc-server.org/t/issue-with-deleting-incoming-dicoms-when-maximumstoragesize-is-reached/3510
**Category:** General
**Created:** [May 17, 2023, 2:01pm UTC](https://discourse.orthanc-server.org/t/issue-with-deleting-incoming-dicoms-when-maximumstoragesize-is-reached/3510 "2023-05-17T14:01:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mzielen](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@mzielen](https://discourse.orthanc-server.org/u/mzielen)
#### Post date: [May 17, 2023, 2:01pm UTC](https://discourse.orthanc-server.org/t/issue-with-deleting-incoming-dicoms-when-maximumstoragesize-is-reached/3510/1 "2023-05-17T14:01:45Z")

</div>

Hello.

I found some feature that looks like bug or unintended behavior.  
In some cases:

- if “MaximumStorageMode” is set to “Reject”
- if “MaximumStorageMode” is set to “Recycle” and incoming dicom is large (maximumStorageSize \< addedInstanceSize)  
then exception ErrorCode\_FullStorage is raised  
Therefore incoming dicoms:
- are not stored in database (that is OK)
- are not deleted from disk (that is not OK)

I looked into the source code and I think that you probably need to catch `ErrorCode_FullStorage` in `ServerContext.cpp::ServerContext::StoreResult ServerContext::StoreAfterTranscoding(...)`

Something like:

```auto
      try {
        result.SetStatus(index_.Store(
          instanceMetadata, summary, attachments, dicom.GetMetadata(), dicom.GetOrigin(), overwrite,
          hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset, isReconstruct));
      } 
      catch (OrthancException& e)
      {
        if (e.GetErrorCode() == ErrorCode_FullStorage)
        {
          LOG(INFO) << "Store returned status: " << result.GetStatus();
        } else {
          throw;
        }
      }

```

It looks that if `result.GetStatus()` != `StoreStatus_Success` then the incoming dicom is deleted in following instructions in this function.

Kind regards,  
Marcin

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 22, 2023, 1:04pm UTC](https://discourse.orthanc-server.org/t/issue-with-deleting-incoming-dicoms-when-maximumstoragesize-is-reached/3510/2 "2023-05-22T13:04:35Z")

</div>

Hi Marcin,

Thanks for reporting this issue.  
This has now been fixed in:

- this orthanc [commit](https://hg.orthanc-server.com/orthanc/rev/5053a10da5a2)
- this [integration tests](https://hg.orthanc-server.com/orthanc-tests/rev/d9d059c6082d)

Best regards,

Alain.

---

<div class="post-metadata">

### Author: ![mzielen](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@mzielen](https://discourse.orthanc-server.org/u/mzielen)
#### Post date: [May 23, 2023, 3:05pm UTC](https://discourse.orthanc-server.org/t/issue-with-deleting-incoming-dicoms-when-maximumstoragesize-is-reached/3510/3 "2023-05-23T15:05:51Z")

</div>

Thanks a lot for quick response, it works correctly now.

Best regards,  
Marcin
