Skip to content

An app's private loopback port is picked without checking it is free, so it can collide with another app's public port #526

Closed

Description

@nixfred

What happens

placeApp() in omarchyd/apps.mjs (~lines 1483-1486) picks the loopback port that Compose will publish for an app's web service:

const used = takenLoopbacks(app.id)          // loopback ports of OTHER apps only
...
let p = 20_000 + (parseInt(createHash('sha256').update(app.id).digest('hex').slice(0, 4), 16) % 9000)
while (used.has(p)) p++

The starting port is a hash of the app id, and the only thing it avoids is another app's loopback port. It does not avoid:

  • the public port of any installed app (the gateway listens on 0.0.0.0:<port>),
  • a port that something else on the server already listens on (portFree() is used for public ports in install() but not here).

The public-port check in install() rejects only ports < 1024, > 65535 and the reserved range 40000-49999, so a listing may legitimately use a port inside 20000-28999. If it equals the loopback port that another app's id hashes to, docker-compose up for the second app fails with "address already in use" and the install ends in an error. Because the port is a hash of the id, it fails the same way on every retry and on every update, until the other app is removed.

How to reproduce

The loopback port for the app id foo is 22302. I installed an app bar whose listing says port: 22302, then foo (web service, web: {service: web, port: 80}), through createApps() with a fake run:

apps.list -> bar port 22302 ; foo port 9001, internalPort 22302
compose.omarchy.yml of foo:  ports: ["127.0.0.1:22302:80"]

bar's gateway would be bound to 0.0.0.0:22302 at that point (it has a web page in a real install), so Compose cannot publish 127.0.0.1:22302 for foo. Expected: foo gets the next free loopback port.

Suggested fix

In the allocation loops (placeApp, systemPortFor) also skip state.apps public/view ports and any port for which portFree() is false.

Environment

Omarchy Server main (6aa7f7d, 0.9.52), Node 26.

Activity

  1. calledtoconstruct commented on Nov 22, 2026

    @calledtoconstruct
    Collaborator

    Working to resolve this.

    No open pull request references this issue, and no one has commented that they are working on it.

    #342, #525, #524, #527, #133, #102, #777, #129, #239, #243, #236, #233, #232, #142, #242, and #443 share the app store with this and will land in one pull request.

    🤖 Generated with Grok 4.7

  2. calledtoconstruct commented on Nov 22, 2026

    @calledtoconstruct
    Collaborator

    Thanks @nixfred. A private loopback port skips another app’s public port and a port that is already in use. This ships in #876.

    🤖 Generated with Grok 4.7

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

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