Skip to content

Fix operation concurrency and response handling#4096

Open
Bojan131 wants to merge 1 commit intov8/developfrom
fix/operation-concurrency
Open

Fix operation concurrency and response handling#4096
Bojan131 wants to merge 1 commit intov8/developfrom
fix/operation-concurrency

Conversation

@Bojan131
Copy link
Collaborator

What

Fixes a concurrency issue where all publish/get/update operations shared a single global mutex per service type, and a race condition where the client would poll for results before signatures were ready.

Changes

Per-operation mutex (operation-service.js + all service files)

  • Moved the Mutex from each individual service (publish-service, get-service, ask-service, etc.) into the base OperationService
  • Each operationId now gets its own mutex instead of sharing one globally. This means parallel publishes don't block each other anymore.
  • Mutexes are cleaned up when operation completes or fails

MinAcksReached ordering (publish-service.js)

  • updateMinAcksReached is now called before markOperationAsCompleted, not after
  • Previously the client could poll the result, see COMPLETED status, but minAcksReached would still be false because the flag update hadn't run yet

Result controller fix (result-http-api-controller-v1.js)

  • Signatures are now returned when status is COMPLETED even if minAcksReached flag wasn't explicitly set (handles the ordering race from the client side too)
  • Added try/catch around signature file loading so a missing file doesn't crash the response

Why

Under parallel load, the global mutex was serializing all operations of the same type. This was unnecessary since operations are independent. The minAcksReached race condition was causing the dkg.js client to get incomplete responses and throw "cannot destructure property identityId" errors.

Made with Cursor

- Move mutex from individual services to base OperationService with per-operation granularity
- Previously all operations shared one global mutex per service, which caused unnecessary blocking
  between unrelated operations. Now each operationId gets its own mutex.
- Clean up mutex when operation completes or fails to prevent memory buildup
- Fix updateMinAcksReached ordering in publish-service — was being called after markOperationAsCompleted
  which could cause a race where the result API returns before the flag is set
- Fix result controller to return signatures when status is COMPLETED even if minAcksReached flag
  wasn't set yet (handles the race condition from the client side too)
- Add try/catch around signature loading in result controller to not crash on missing files

Made-with: Cursor
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.

1 participant