Skip to content

Set up TLS, the gRPC listener and signals before starting the node - #330

Merged
benthecarman merged 1 commit into
lightningdevkit:mainfrom
ajaysehwal:bind-before-node-start
Nov 11, 2026
Merged

benthecarman merged 1 commit into
lightningdevkit:mainfrom
ajaysehwal:bind-before-node-start

Conversation

@ajaysehwal

@ajaysehwal ajaysehwal commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

We loaded the TLS config, bound the gRPC port and registered the signal handlers only after node.start(). If the port was already in use we panicked, which with panic = "abort" kills a node that is already running without calling node.stop(). A SIGTERM or Ctrl-C during node.start() killed the process without a graceful shutdown.

Now we load the TLS config and bind the listener before starting the node, exiting with an error if either fails, and register the SIGHUP, SIGTERM and SIGINT handlers up front. Signals received during startup are handled by the main loop once the node is running. This still happens after building the node, so a restarting instance keeps waiting for a Postgres lease held by the previous one.

Tested against a mock Esplora server:

  • Port already in use: before, the node started and then aborted (exit -6). Now it exits with Failed to bind gRPC service address before starting the node.
  • SIGTERM during node.start(): before, the process was killed (exit -15). Now it shuts down gracefully (exit 0).

Added e2e test test_config_fail_grpc_address_in_use. It compiles, but I couldn't run it locally because it needs bitcoind.

@ldk-reviews-bot

ldk-reviews-bot commented Nov 9, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @benthecarman as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ajaysehwal

Copy link
Copy Markdown
Contributor Author

Hi @benthecarman, when you have time, could you take a look at this? It sets up TLS, the gRPC bind and the signal handlers before node.start(), so a port conflict or TLS error no longer leaves a running node that then aborts, and a SIGTERM during startup shuts down gracefully instead of killing the process. The second commit adds a flock on the network directory so two instances can't share one SQLite store.

One decision I'd like your input on: the lock adds a direct libc dependency (already in the lock file via other crates) and one unsafe call. If you'd rather not have that, I can drop it from this PR (or open it separately) and keep only the first commit. I added the "proof" output for each case to the description.

@Anyitechs Anyitechs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested ACK 6b1396f!

Tested the changes on my ubuntu server and both work well. The changes proposed in the second commit makes sense as well, but I don't have an opinion on the approach.

Comment thread e2e-tests/src/lib.rs Resolved

@benthecarman benthecarman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the second commit is not needed, we do this in our database already.

also please don't just have AI write your entire PR desc and commit message without you cleaning it up first

@ajaysehwal
ajaysehwal force-pushed the bind-before-node-start branch from c76e970 to 314b973 Compare November 10, 2026 01:55
@ajaysehwal

ajaysehwal commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

the second commit is not needed, we do this in our database already.

also please don't just have AI write your entire PR desc and commit message without you cleaning it up first

Thanks, dropped the lock commit and shortened the commit message and description. I had added the long write-up and repro output just to show the issue was real, but I understand it was too much. I’ve kept only a short summary.

@ajaysehwal
ajaysehwal force-pushed the bind-before-node-start branch from 314b973 to 7f9ba71 Compare November 10, 2026 01:58
@ajaysehwal ajaysehwal changed the title Set up TLS and signals before starting the node, and lock the storage directory Set up TLS, the gRPC listener and signals before starting the node Nov 10, 2026
Comment thread e2e-tests/tests/config.rs Resolved
Comment thread ldk-server/src/main.rs Resolved
We loaded the TLS config, bound the gRPC port and registered the signal
handlers only after `node.start()`. If the port was already in use we
panicked, which with `panic = "abort"` kills a node that is already
running without `node.stop()`. A TLS setup failure did the same, and a
SIGTERM or Ctrl-C received during `node.start()` killed the process
without a graceful shutdown.

Now we load the TLS config and bind the listener before starting the
node, exiting with an error if either fails, and register the SIGHUP,
SIGTERM and SIGINT handlers up front. Signals received during startup
are handled by the main loop once the node is running. This still
happens after building the node, so a restarting instance keeps waiting
for a Postgres lease held by the previous one.
@benthecarman
benthecarman merged commit 0c332f5 into lightningdevkit:main Nov 11, 2026
9 checks passed
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.

4 participants