Skip to content

Fix idle-in-transaction state by adding explicit transaction boundaries#281

Draft
Copilot wants to merge 11 commits into
tf_nira_devfrom
copilot/update-workflow-instance-query
Draft

Fix idle-in-transaction state by adding explicit transaction boundaries#281
Copilot wants to merge 11 commits into
tf_nira_devfrom
copilot/update-workflow-instance-query

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 11, 2026

Problem

Database connections entering idle in transaction state for query filtering by workflow_instance_id. Connections held open during long-running operations (HTTP calls, biometric processing) occurring after data fetch, blocking VACUUM and exhausting connection pool.

Root Cause

SyncRegistrationServiceImpl read methods lack explicit transaction boundaries. Spring Data JPA opens implicit transactions that remain open through method return, keeping connections active while calling code executes business logic.

Example flow:

// Connection opens transaction here
SyncRegistrationEntity entity = service.findByWorkflowInstanceId(id);
// Transaction still open, connection idle
packetManagerService.getBiometrics(...);  // 2s
authService.authenticate(...);             // 3s  
// Transaction finally closes

Changes

Added transaction annotations to read methods

@Override
@Transactional(readOnly = true)
public SyncRegistrationEntity findByWorkflowInstanceId(String workflowInstanceId) {
    return syncRegistrationDao.findByWorkflowInstanceId(workflowInstanceId);
}

Modified methods (5 total in SyncRegistrationServiceImpl):

  • findByWorkflowInstanceId()
  • findByRegistrationId()
  • findByRegistrationIdAndAdditionalInfoReqId()
  • findByPacketId()
  • findByAdditionalInfoReqId()

Added monitoring tools

  • monitoring/idle_in_transaction_monitor.sql - PostgreSQL queries to track idle connections
  • Documentation covering verification and deployment

Impact

  • Transactions commit immediately after data fetch
  • Connections released before business logic execution
  • Read-only flag enables database optimizations
  • Zero behavioral changes (backwards compatible)

Verification:

SELECT count(*) FROM pg_stat_activity 
WHERE state = 'idle in transaction' AND datname = 'mosip_regprc';
-- Expected: 0 (previously: multiple)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits March 11, 2026 01:30
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Copilot AI changed the title [WIP] Update query for retrieving workflow instance data Document SQL query execution points for workflow_instance_id lookups Mar 11, 2026
Copilot AI and others added 4 commits March 11, 2026 02:13
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Co-authored-by: Nagarjunakuchi88 <64436505+Nagarjunakuchi88@users.noreply.github.com>
Copilot AI changed the title Document SQL query execution points for workflow_instance_id lookups Fix idle-in-transaction state by adding explicit transaction boundaries Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants