Skip to content

fix: replaced port character sum with a cksum hash - #75

Merged
CaddyDz merged 1 commit into
masterfrom
fix/port-hash
Oct 17, 2026
Merged

CaddyDz merged 1 commit into
masterfrom
fix/port-hash

Conversation

@CaddyDz

@CaddyDz CaddyDz commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Problem

port <string> summed character codes, so:

  • anagrams collided (ab/ba, web-api/api-web)
  • short names clustered around 49.5k–51.5k
  • it forked printf once per character
  • word, sum, port, … leaked into the calling shell

Changes

  • port now hashes with cksum (POSIX CRC) into 49152–65535, uses local, prints usage to stderr and returns 1 without an argument
  • port --check <string> warns on stderr when the port is listening locally, published by a running container, or written in a docker-compose*.yml/.env under ~/Code; it still prints the number and exits 0
  • Old algorithm kept as port_legacy, because these files hardcode values it generated (left untouched):
    • FraudCentral docker-compose.yml → 50427 (fraudcentral)
    • Roboguard .env.example → 50117 (roboguard), 49921 (control)
    • Sockets docker-compose.yml → 50117 in comments only
    • xeldex docker-compose.yml → 49802 (xeldex)

Testing

name legacy new
fraudcentral 50427 55514
dsalim 49786 58537
crm 49474 58623
control 49921 57632
roboguard 50117 52031
crazytel-ui 50297 49804
ab / ba 49347 / 49347 56659 / 63241
  • _port_check 8080 reports the local listener, the traefik container, and the compose/.env files that contain 8080
  • port / port --check with no string → usage on stderr, exit 1
  • No variables leak into the calling shell

The old sum ignored letter order (anagrams collided) and clustered short
names around 49.5k-51.5k. Kept it as `port_legacy` since FraudCentral,
Roboguard, Sockets and xeldex hardcode values it generated. Added
`--check` to warn when the port is already taken, and scoped all
variables with `local`.
@CaddyDz CaddyDz added this to the Shell environment cleanup milestone Oct 17, 2026
@CaddyDz CaddyDz added bug Something isn't working enhancement New feature or request DX Improving development experience perf Performance improvements labels Oct 17, 2026
@CaddyDz CaddyDz self-assigned this Oct 17, 2026
@CaddyDz
CaddyDz merged commit f7240d8 into master Oct 17, 2026
1 check passed
@CaddyDz
CaddyDz deleted the fix/port-hash branch October 17, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working DX Improving development experience enhancement New feature or request perf Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant