Skip to content

webhook: fail fast without an ngrok authtoken, report connection failures, bound the connect - #108

Open
sunilmehta-si wants to merge 1 commit into
xdevplatform:mainfrom
sunilmehta-si:fix-webhook-missing-ngrok-token
Open

sunilmehta-si wants to merge 1 commit into
xdevplatform:mainfrom
sunilmehta-si:fix-webhook-missing-ngrok-token

Conversation

@sunilmehta-si

Copy link
Copy Markdown

Summary

Fixes #107. xurl webhook start accepted a blank authtoken prompt with NGROK_AUTHTOKEN unset, passed an empty token to the ngrok SDK, and then sat in connection setup with no tunnel URL and no error. The SDK treats the authentication failure as temporary and retries it forever, so a failed start was indistinguishable from a slow one until the process was killed.

Three changes in cli/webhook.go:

  • The token is resolved up front: the prompt, then NGROK_AUTHTOKEN. With neither, the command exits 1 with no ngrok authtoken: enter one at the prompt or set NGROK_AUTHTOKEN (get it from https://dashboard.ngrok.com/get-started/your-authtoken).
  • Every failed connection attempt is printed through ngrok.WithDisconnectHandler, so an invalid token shows its ERR_NGROK_105 message instead of nothing.
  • A new --connect-timeout (default 30s) cancels the connect context if the tunnel is not up in time, so ngrok.Listen returns an error that names the last failure. The timer is stopped once the tunnel is up, so the session's own reconnects later on are unaffected.

resolveNgrokAuthtoken is a small pure function with a table test (cli/webhook_test.go); the webhook command had no tests before. CHANGELOG has an entry under Unreleased.

Verification

Ran the reproduction script from #107 (fresh HOME, synthetic OAuth 1.0a credentials, blank line to the prompt, no NGROK_AUTHTOKEN):

  • main at 18dcb44: still running after 30 s, last line Configuring ngrok to forward to local port: 8080.
  • This branch: exits 1 in 0.0 s with the message above.
  • This branch with a bogus token and --connect-timeout 6s: prints ngrok: authentication failed: The authtoken you specified does not look like a proper ngrok authtoken ... ERR_NGROK_105 on each attempt, then Error starting ngrok tunnel: not connected after 6s; the last error was: ... and exits 1.

gofmt -l . clean, go vet ./... clean, go test ./... passes (Go 1.27.3, darwin/arm64). Not tested with a valid ngrok token (I don't have an ngrok account); the success path only differs in that the timer is stopped after Listen returns.

…ures, bound the connect

A blank prompt with NGROK_AUTHTOKEN unset went to ngrok.WithAuthtokenFromEnv()
with an empty token. The SDK treats the authentication failure as temporary and
retries it forever, so `xurl webhook start` sat in connection setup with no
tunnel URL and no error until it was killed.

- Resolve the token up front (prompt, then NGROK_AUTHTOKEN) and exit 1 with a
  message that says how to supply one when there is none.
- Print each connection failure through ngrok.WithDisconnectHandler, so an
  invalid token shows its ERR_NGROK_105 instead of nothing.
- Add --connect-timeout (default 30s): the context is cancelled if the tunnel
  is not up in time, which makes ngrok.Listen return an error naming the last
  failure. The timer stops once the tunnel is up, so reconnects are unaffected.

Fixes xdevplatform#107
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

fix(webhook): missing ngrok token leaves startup retrying silently

2 participants