Skip to content

fix: infinite loop in logger color assignment when all ANSI codes are allocated #116

@tarone-saloni

Description

@tarone-saloni

Problem:

In src/utils/logger.ts:44-58, assignColorToWorker uses a do...while loop that randomly picks from a pool of 16 ANSI color codes until it finds an unassigned one.

Actual Behaviour:

Each new deployment consumes one color code from the 16-entry ANSICode array.
Once 16 deployments are active, all codes are marked as used in assignedColorCodes.
Any 17th deployment triggers assignColorToWorker, which enters do { colorCode = random pick } while (assignedColorCodes[colorCode]) — since every code is taken, this condition is always true and the loop never terminates.
The Node.js event loop is blocked entirely, making the server unresponsive to all requests.
The code has a TODO comment acknowledging this exact problem but it has not been fixed.

Expected Behaviour:

Color assignment should cycle through the palette (e.g., modulo indexing) or reuse the least-recently-used color once all codes are allocated, rather than spinning indefinitely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions