Skip to content

Implement netcat listener for open port scanning on Render#1607

Merged
lightwalker-eth merged 4 commits intomainfrom
opdd
Feb 6, 2026
Merged

Implement netcat listener for open port scanning on Render#1607
lightwalker-eth merged 4 commits intomainfrom
opdd

Conversation

@djstrong
Copy link
Copy Markdown
Member

@djstrong djstrong commented Feb 5, 2026

Lite PR

Summary

  • Added netcat listener during container initialization to keep port open while database downloads/validates
  • Added netcat-openbsd package to Dockerfile dependencies
  • Netcat listener is automatically cleaned up before the actual server starts

Why

During container initialization, ENSRainbow can take a long time to download and validate the database (up to 20 minutes). Without a listener on the port during this phase, Render health checks fail and orchestration systems may mark the container as unhealthy or restart it prematurely. The netcat listener keeps the port open and accepts connections during initialization, then is cleanly terminated when the actual server is ready to start.


Testing

  • Tested on Render

Notes for Reviewer (Optional)

  • It is a quick workaround for Render.

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

Added netcat listener for incoming connections and cleanup function on exit.
Copilot AI review requested due to automatic review settings February 5, 2026 15:36
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped Feb 6, 2026 10:25am
ensnode.io Skipped Skipped Feb 6, 2026 10:25am
ensrainbow.io Skipped Skipped Feb 6, 2026 10:25am

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 5, 2026

⚠️ No Changeset found

Latest commit: ea2401e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Adds a netcat-based background listener to container init: the Dockerfile installs netcat-openbsd, and entrypoint.sh starts a listener during database download/validation, then cleans it up before the application server binds the service port.

Changes

Cohort / File(s) Summary
Dockerfile Runtime Dependencies
apps/ensrainbow/Dockerfile
Adds netcat-openbsd to the runtime stage and includes comments explaining the listener's purpose and caveats (listener does not serve HTTP).
Entrypoint Initialization Logic
apps/ensrainbow/scripts/entrypoint.sh
Starts a background netcat listener, adds cleanup_nc() and trap cleanup_nc EXIT, ensures listener is terminated and trap removed before server startup, and inserts a short delay to allow port release.

Sequence Diagram

sequenceDiagram
    participant Container as Container Init
    participant Netcat as Netcat Listener
    participant DB as Database Operations
    participant Server as Application Server

    Container->>Netcat: Start background listener on service port
    Note over Netcat: Holds port while DB download/validation run\n(no HTTP responses)
    Container->>DB: Download and validate database
    DB-->>Container: Database ready
    Container->>Netcat: Call cleanup_nc() (via EXIT trap or explicit)
    Netcat->>Netcat: Terminate process (release port)
    Netcat-->>Container: Port released
    Container->>Container: Short delay to ensure port free
    Container->>Server: Start application server
    Server->>Server: Bind to service port
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I held the port while the data came in,
A quiet listener, patient and thin,
When downloads finished and checks were done,
I hopped away so the server could run,
Little paws tidy — the job's neatly spun.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: implementing a netcat listener for Render deployment.
Description check ✅ Passed The description follows the template structure with all required sections completed: Summary, Why, Testing, Pre-Review Checklist, and includes optional Notes for Reviewer.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch opdd

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to address healthcheck issues during the long startup period of the ENSRainbow service by adding a netcat listener that occupies the application port while the database is being downloaded and validated. The ensrainbow service has a 20-minute start period because it downloads and validates a large database before starting the actual server.

Changes:

  • Added netcat-openbsd package to the Docker image
  • Started a netcat listener on the application port during startup to respond to health checks
  • Added cleanup logic to kill the netcat listener before starting the actual ENSRainbow server

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
apps/ensrainbow/Dockerfile Added netcat-openbsd package installation to support the netcat listener
apps/ensrainbow/scripts/entrypoint.sh Added netcat listener startup, cleanup function, and pre-server cleanup logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/Dockerfile
Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 5, 2026

🚀 Preview Packages - opdd

NPM Packages:

# Install latest preview for this branch
pnpm add @ensnode/datasources@preview-opdd
pnpm add @ensnode/ensnode-react@preview-opdd
pnpm add @ensnode/ensrainbow-sdk@preview-opdd
pnpm add @ensnode/ensnode-schema@preview-opdd
pnpm add @ensnode/ensnode-sdk@preview-opdd
pnpm add @ensnode/ponder-metadata@preview-opdd
pnpm add @ensnode/ponder-sdk@preview-opdd
pnpm add @ensnode/ponder-subgraph@preview-opdd
pnpm add @ensnode/ens-referrals@preview-opdd
pnpm add @ensnode/namehash-ui@preview-opdd

# Or install specific version
pnpm add @ensnode/ensnode-sdk@0.0.0-preview-opdd-20260205153739

Docker Images:

docker pull ghcr.io/namehash/ensnode/ensindexer:preview-opdd-aa06b11d
docker pull ghcr.io/namehash/ensnode/ensadmin:preview-opdd-aa06b11d
docker pull ghcr.io/namehash/ensnode/ensapi:preview-opdd-aa06b11d
docker pull ghcr.io/namehash/ensnode/ensrainbow:preview-opdd-aa06b11d

Build Info:

  • 🎯 Target: 📦 NPM packages + 🐳 Docker images
  • 📦 Version: 0.0.0-preview-opdd-20260205153739
  • 📝 Commit: aa06b11d
  • 🌿 Branch: opdd
  • ⏰ Built: 2026-02-05 15:41:39 UTC
  • 🔗 Workflow Run

🤖 This comment will be updated on subsequent publishing of release previews from the branch associated with this PR

Note: Preview packages are managed by changesets. NPM dist-tags can be cleaned up manually using npm dist-tag rm @ensnode/ensnode-sdk preview-opdd

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@apps/ensrainbow/Dockerfile`:
- Line 5: The RUN instruction installing packages in the Dockerfile ("RUN
apt-get update && apt-get install -y wget tar netcat-openbsd && rm -rf
/var/lib/apt/lists/*") should add --no-install-recommends to apt-get install to
avoid pulling recommended packages and reduce image size; update that command to
use apt-get install -y --no-install-recommends and, if deterministic builds are
required, pin package versions (e.g., package=version) or add an APT sources
snapshot so the RUN line (the installation step) produces reproducible, smaller
images.

In `@apps/ensrainbow/scripts/entrypoint.sh`:
- Around line 144-149: After calling cleanup_nc, immediately verify that the
netcat process was actually terminated (e.g., check NC_PID/process existence
with kill -0 or ps) before clearing NC_PID and removing the EXIT trap; if the
process still exists or the PID was reused, log an error and exit non-zero to
fail fast rather than proceeding to start the server. Ensure the check
references cleanup_nc, NC_PID and the trap - EXIT sequence so the script only
clears NC_PID and removes the trap after confirming netcat is no longer running.

Comment thread apps/ensrainbow/Dockerfile
Comment thread apps/ensrainbow/scripts/entrypoint.sh Outdated
Comment thread apps/ensrainbow/scripts/entrypoint.sh
@djstrong djstrong changed the title Opdd Implement netcat listener for open port scanning on Render Feb 5, 2026
@djstrong djstrong marked this pull request as ready for review February 5, 2026 20:56
@djstrong djstrong requested a review from a team as a code owner February 5, 2026 20:56
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Feb 5, 2026

Greptile Overview

Greptile Summary

This PR keeps Render health checks from failing during ENSRainbow’s long initialization by starting a background nc listener on $PORT in apps/ensrainbow/scripts/entrypoint.sh, and adds netcat-openbsd to the runtime image (apps/ensrainbow/Dockerfile). Before launching the actual server (pnpm run serve), the entrypoint attempts to kill the netcat process and removes the EXIT trap so the real server can bind the port.

Key integration point: the listener runs only during the DB download/validate phase and is intended to be torn down immediately before exec pnpm run serve --port $PORT.

Confidence Score: 3/5

  • Moderately safe to merge, but there is a real risk of startup failures due to port-binding behavior in the init listener.
  • Changes are small and localized, but the current netcat startup/cleanup does not validate that nc successfully bound the port or that the port is definitely freed before starting pnpm serve, which can produce deterministic boot failures in some environments/nc behaviors.
  • apps/ensrainbow/scripts/entrypoint.sh

Important Files Changed

Filename Overview
apps/ensrainbow/Dockerfile Adds netcat-openbsd to runtime apt dependencies so entrypoint can run nc during init.
apps/ensrainbow/scripts/entrypoint.sh Starts a background nc listener during init and kills it before starting the server; cleanup works but listener can fail to start silently and can bind the port in a way that prevents the server from starting.

Sequence Diagram

sequenceDiagram
    participant Orchestrator as Render/Orchestrator
    participant Entrypoint as entrypoint.sh
    participant NC as nc listener
    participant Downloader as download/validate
    participant Server as pnpm serve

    Orchestrator->>Entrypoint: Start container (PORT set)
    Entrypoint->>NC: nc -lk -p $PORT (background)
    Orchestrator->>NC: Health checks / connections
    Entrypoint->>Downloader: Download + extract DB (if needed)
    Entrypoint->>Downloader: pnpm validate:lite
    Entrypoint->>NC: cleanup_nc() / kill $NC_PID
    Entrypoint->>Server: exec pnpm run serve --port $PORT
    Orchestrator->>Server: Health checks / traffic
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread apps/ensrainbow/scripts/entrypoint.sh
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
terraform/modules/ensadmin/main.tf (1)

1-52: ⚠️ Potential issue | 🟡 Minor

Run terraform fmt to fix CI failure.

The CI pipeline reports formatting differences in this file; please reformat and re-run the check.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@terraform/modules/ensadmin/main.tf`:
- Around line 42-45: The joined FQDN list built for
NEXT_PUBLIC_SERVER_CONNECTION_LIBRARY uses values(local.api_fqdns) which is
unordered; change the iteration to use a deterministic ordering such as sorting
keys(local.api_fqdns) and then mapping those keys to their FQDN values so the
join(...) produces a stable, repeatable string (update the expression that
constructs NEXT_PUBLIC_SERVER_CONNECTION_LIBRARY to iterate over sorted keys and
build "https://${fqdn}" from the corresponding values).

Comment thread terraform/modules/ensadmin/main.tf Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread terraform/modules/ensadmin/main.tf Outdated
Comment thread terraform/modules/ensadmin/main.tf Outdated
Comment thread terraform/modules/ensrainbow/main.tf Outdated
Copy link
Copy Markdown
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djstrong Shared a few small comments. There's also a number of comments from AI agents that look to have good feedback. Appreciate if you can review all AI agent feedback and resolve as you think is best. Thanks

Comment thread apps/ensrainbow/Dockerfile
Comment thread apps/ensrainbow/scripts/entrypoint.sh
Copilot AI review requested due to automatic review settings February 6, 2026 09:19
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io February 6, 2026 09:20 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io February 6, 2026 09:20 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensnode.io February 6, 2026 09:20 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh Outdated
Comment thread apps/ensrainbow/Dockerfile
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@apps/ensrainbow/scripts/entrypoint.sh`:
- Around line 152-157: The fixed 2-second sleep in the entrypoint is unnecessary
and adds startup latency; remove or shorten it and instead ensure the port is
free after cleanup_nc returns (which already does kill + wait). Update the block
around the exec pnpm run serve line to either remove sleep entirely or replace
sleep 2 with sleep 0.5, or better implement a short fail-fast guard that polls
the port (loop checking that nc/netstat/lsof shows no listener) and only
proceeds when the port is confirmed free; refer to the existing cleanup_nc
helper to verify it has completed before starting the server and use that helper
as the trigger to start exec pnpm run serve --port "${PORT}" --data-dir
"${DB_SUBDIR_PATH}".
- Around line 39-55: Move the cleanup function definition (cleanup_nc) and the
trap registration (trap cleanup_nc EXIT) to before the nc invocation so the
listener cannot be orphaned if the script exits; start nc using the portable
positional form nc -lk "${PORT}" and background it into NC_PID, then immediately
verify the listener started (e.g., short sleep then ensure NC_PID is alive with
kill -0 "$NC_PID" and/or confirm the port is bound) and fail early if
verification fails so set -e surfaces bind errors.

Comment thread apps/ensrainbow/scripts/entrypoint.sh
Comment thread apps/ensrainbow/scripts/entrypoint.sh
@vercel vercel Bot temporarily deployed to Preview – ensnode.io February 6, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io February 6, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io February 6, 2026 10:25 Inactive
Copy link
Copy Markdown
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djstrong Really appreciate your updates here. Looks good 👍

@lightwalker-eth lightwalker-eth merged commit a64a1da into main Feb 6, 2026
16 checks passed
@lightwalker-eth lightwalker-eth deleted the opdd branch February 6, 2026 10:46
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.

3 participants