# Bug OP-17020 - ActiveRecord::Deadlocked on Attachments::FinishDirectUploadJob#perform leading to lost uploads

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-17020

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 16.1.1 |
| Observed in versions |  |
| Sprint | 16.1.1 |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable | Jens Ulferts |
| Product manager |  |
| Developers | Jens Ulferts |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Steps to reproduce

1.  Unclear (AppSignal report - Probably related to bulk uploading files. Happened on a wiki page)
    

### What is the buggy behavior?

*   The files are not actually uploaded and are ultimately lost.
    

### What is the expected behavior?

1.  Files uploaded
    

### **Logs**

From AppSignal

```text
PG::TRDeadlockDetected: ERROR:  deadlock detected
DETAIL:  Process 26119 waits for ShareLock on transaction 73588604; blocked by process 19559.
Process 19559 waits for ShareLock on transaction 73588610; blocked by process 26119.
HINT:  See server log for query details.
CONTEXT:  while inserting index tuple (4904,6) in relation "index_journals_on_journable_type_and_journable_id_and_version"
```

Stacktrace:

<figure class="table op-uc-figure_align-center op-uc-figure" style="width:1680px;"><table class="op-uc-table" style="border:0px solid rgb(217, 221, 231);"><tbody><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/services/journals/create_service.rb:99 block in Journals::CreateService#create_journal</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/services/journals/create_service.rb:96 Journals::CreateService#create_journal</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/services/journals/create_service.rb:56 block in Journals::CreateService#call</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/services/journals/create_service.rb:55 Journals::CreateService#call</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/attachments/finish_direct_upload_job.rb:125 Attachments::FinishDirectUploadJob#journalize_container</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/attachments/finish_direct_upload_job.rb:54 Attachments::FinishDirectUploadJob#attach_uploaded_file</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/attachments/finish_direct_upload_job.rb:44 block in Attachments::FinishDirectUploadJob#perform</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">lib/open_project/locale_helper.rb:36 OpenProject::LocaleHelper.with_locale_for</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/models/user.rb:538 User.execute_as</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/attachments/finish_direct_upload_job.rb:43 Attachments::FinishDirectUploadJob#perform</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/shared_job_setup.rb:59 block in SharedJobSetup#prepare_job_context</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/shared_job_setup.rb:76 SharedJobSetup#with_clean_request_store</p></td><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 1.25rem 0.5rem 0.625rem;"><p class="op-uc-p"><br></p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell" style="border-bottom-width:1px;border-color:inherit;border-left-width:0px;border-right-width:0px;border-top-width:0px;padding:0.5rem 0.625rem 0.5rem 1.25rem;"><p class="op-uc-p">app/workers/shared_job_setup.rb:55 SharedJobSetup#prepare_job_context</p></td><td class="op-uc-table--cell"><p class="op-uc-p"><br></p></td></tr></tbody></table></figure>

https://appsignal.com/openproject-gmbh/sites/673c529383eb67b55471dda2/exceptions/incidents/728
