Repository navigation
[JIM-349] Parallel import of multiple projects fails with "PG::QueryCancelled" - #27363
Open
ammancilla wants to merge 2 commits into
Open
ammancilla wants to merge 2 commits into
ammancilla wants to merge 2 commits into
Conversation
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer. |
ammancilla
force-pushed
the
bug/jim-349-parallel-import-of-multiple-projects-fails-with-pg-querycancelled
branch
4 times, most recently
from
November 26, 2026 15:56
e151046 to
436fa37
Compare
ammancilla
force-pushed
the
bug/jim-349-parallel-import-of-multiple-projects-fails-with-pg-querycancelled
branch
from
November 27, 2026 08:22
436fa37 to
4cad3fd
Compare
ammancilla
commented
Nov 27, 2026
Comment on lines
+280
to
+290
| def ensure_type_has_custom_fields(type, jira_issue) | ||
| return if new_custom_fields_in_type(jira_issue, type, @custom_field_registry).empty? | ||
|
|
||
| form = type.default_variant.form_configuration | ||
| OpenProject::Mutex.with_advisory_lock_transaction(form, WorkPackageTypes::FormConfiguration::LayoutLock::SUFFIX) do | ||
| type.default_variant.reload | ||
| new_custom_fields = new_custom_fields_in_type(jira_issue, type, @custom_field_registry) | ||
| next if new_custom_fields.empty? | ||
|
|
||
| update_custom_fields_in_type(type, new_custom_fields) | ||
| end |
Member
Author
There was a problem hiding this comment.
This is a second race condition I found, when importing a large remote Jira intance (363 projects, 42k issues). Added the fix as a drive-by.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
https://community.openproject.org/wp/JIM-349
What are you trying to accomplish?
Fix statement timeouts (
PG::QueryCanceled) when several Jira projects are imported at the same time.What approach did you choose and why?
The problem: each Jira issue is imported in one transaction. When that transaction writes a row that the whole import shares, the row stays locked until the transaction commits, so issues from other projects being imported in parallel that need the same row have to wait. The import did such writes in two places:
jira_open_project_referencesfor its type, status and priority.Most issues across projects use the same few types, statuses and priorities, so with many projects the jobs end up waiting for each other until a wait goes past the statement timeout.
The fix keeps the current import structure, but stops writing those import-wide shared rows on every issue:
ON CONFLICT DO NOTHINGinstead ofON CONFLICT DO UPDATE. The first write is final, since an entity is referenced in the same transaction that creates it.Results
The import was run on a large dataset (364 projects, 36,016 issues) with 20 worker threads and a 90 s statement timeout, before and after applying the fix, with the following results:
AI involvement
Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.
Merge checklist