Skip to content

EscrowService generates IDs from Date.now() with no collision protection #211

Description

@meshackyaro

Description

EscrowService.create() (src/escrow/escrow.service.ts) generates escrow IDs as `esc-${Date.now()}` — a millisecond timestamp with no random component. Two escrows created within the same millisecond (entirely possible under concurrent requests, which Node.js's single-threaded event loop can still interleave between the Date.now() call and the Map.set()) get the exact same ID, and the second create() call silently overwrites the first escrow record in the in-memory Map. Compare this to GigService.create() (src/gig/gig.service.ts), which already appends a random suffix (`gig-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`), and DisputeSagaService.escalate() (src/dispute/dispute-saga.service.ts), which does the same for saga IDs — EscrowService is the one core identifier generator that doesn't follow this pattern.

Component

Backend

Difficulty

🟢 Easy

Tasks

  • Change EscrowService.create()'s ID generation to include a random/UUID component, consistent with GigService/DisputeSagaService's pattern (or adopt randomUUID() as used in UserProfileService/MigrationRunnerService)
  • Add a regression test that creates many escrows in a tight loop and asserts all IDs are unique

Acceptance Criteria

  • Escrow IDs are collision-resistant under concurrent creation
  • A test proves no duplicate IDs occur across a burst of rapid create() calls

Estimated Time

1-2 hours

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions