# Orthanc Crashes After Deploying Custom Authentication and Authorization Mechanism

**URL:** https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253
**Category:** General
**Created:** [October 17, 2024, 12:03pm UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253 "2024-10-17T12:03:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![prathyu](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/prathyu/32/1879_2.png) [@prathyu](https://discourse.orthanc-server.org/u/prathyu)
#### Post date: [October 17, 2024, 12:03pm UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253/1 "2024-10-17T12:03:30Z")

</div>

**Hi everyone,**

I’ve implemented custom authentication and authorization mechanisms to control access to Orthanc resources using the `RegisterIncomingHttpRequestFilter` callback method. Everything works fine locally, but after deployment, Orthanc crashes after some time and requires a restart to function again.

Here’s a simplified version of my code:

```auto
import json
from enum import Enum
import orthanc
import pika
import pika.exceptions

def Filter(uri, **request):
    return True
    

def on_change(change_type: orthanc.ChangeType, _level, resource_id: str) -> None:
    """Onchange event handler, registered with Orthanc server."""
    # Event handling logic here...
    .....
    ......

orthanc.RegisterIncomingHttpRequestFilter(Filter)
orthanc.RegisterOnChangeCallback(on_change)

```

### **Problem Description:**

- The custom authentication mechanism works perfectly on my local machine.
- After deploying Orthanc to a server, it runs fine for a while, but after some time, Orthanc fails and stops responding. Restarting the service makes it work again temporarily.
- Even with the simplified filter function (`return True` without any real authentication logic), Orthanc crashes over time
- The `orthanc.RegisterOnChangeCallback(on_change)` function works fine in both local and production environments.
- There are no specific error logs that indicate the cause of the crash.  
but i noticed a logs as,

> E1002 02:57:33.487136 PluginsManager.cpp:153] Exception in database back-end: Database could not serialize access due to concurrent update, the transaction should be retried

version details:  
Orthanc Version:orthancteam/orthanc:23.11.0  
Pyhton Plugin Version : 4.1

Added logs to track when the `Filter` methods are triggered, but that hasn’t led to finding the root cause yet

Any insights, suggestions, or guidance on how to further debug or resolve this would be greatly appreciated!

Thanks in advance for your help.

---

<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: [October 18, 2024, 8:50am UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253/2 "2024-10-18T08:50:31Z")

</div>

Hi @prathyu

> [@prathyu](#):
>
> E1002 02:57:33.487136 PluginsManager.cpp:153] Exception in database back-end: Database could not serialize access due to concurrent update, the transaction should be retried

This is actually a false error message. the transaction is actually retried.

> [@prathyu](#):
>
> Any insights, suggestions, or guidance on how to further debug or resolve this would be greatly appreciated!

I must admit that I’m quite clueless on this one. I would of course check the verbose logs to know what Orthanc was doing when it crashed and I would also monitor the memory usage of the container in case there is a memory leak somewhere (there are no know leaks in Orthanc but the python code might introduce some).

Upgrading to latest version is also always a good idea before starting any kind of investigations.

Best,

Alain

---

<div class="post-metadata">

### Author: ![prathyu](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/prathyu/32/1879_2.png) [@prathyu](https://discourse.orthanc-server.org/u/prathyu)
#### Post date: [October 21, 2024, 8:20am UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253/3 "2024-10-21T08:20:24Z")

</div>

Hi Alain  
Thanks for the response, like you said I’ve checked the latest version, and it looks like this issue is resolved there. However, I have some concerns about upgrading:

**Current Setup:**

- We’re currently running Orthanc version 23.11.0 with around 32,000 studies in the database.
- I noticed that the latest version introduces schema changes.

My Questions:  
1) **Will upgrading to the latest version result in data loss?**

- I’m worried about losing our existing studies due to schema changes. How does Orthanc handle data migration during upgrades with schema modifications?

2) **What is the best way to migrate data properly?**

3) **Are there any recommended steps to ensure a safe upgrade?**

Any guidance or advice from others who have done this type of upgrade would be greatly appreciated!

Thanks again for the support.

---

<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: [October 21, 2024, 12:54pm UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253/4 "2024-10-21T12:54:56Z")

</div>

Hi @prathyu

Actually, in general, you should not worry about the upgrades, Orthanc will handle it for you. The main schema version (v 6) has not changed since December … 2015 ;-).

Some Orthanc upgrade might introduce small modifications in the DB schema. If you are using SQLite, there’s nothing to worry about. If you are using PostgreSQL and have very large DBs and multiple Orthanc instances connected to the same DB, you should read [this section](https://orthanc.uclouvain.be/book/plugins/postgresql.html#note-for-large-databases-and-multiple-orthanc-instances) of the documentation to make sure your downtime is minimized.

Hope this helps,

Alain.

---

<div class="post-metadata">

### Author: ![prathyu](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/prathyu/32/1879_2.png) [@prathyu](https://discourse.orthanc-server.org/u/prathyu)
#### Post date: [November 5, 2024, 10:30am UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253/5 "2024-11-05T10:30:06Z")

</div>

Hi Alain  
Thanks for the insights! I have one more question:

**What happens to incoming studies during the upgrade process?**  
If studies are sent to Orthanc during the upgrade, is there a risk of losing those studies?  
Should we plan to stop incoming data temporarily, or are there any best practices to manage this?

Thanks for the guidance!

---

<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: [November 6, 2024, 8:59am UTC](https://discourse.orthanc-server.org/t/orthanc-crashes-after-deploying-custom-authentication-and-authorization-mechanism/5253/6 "2024-11-06T08:59:13Z")

</div>

> [@prathyu](#):
>
> What happens to incoming studies during the upgrade process?

Orthanc will actually upgrade the DB during its startup before the DICOM and HTTP Ports are opened. Therefore, clients will not be able to connect and push new studies.

HTH,

Alain
