Skip to content

fix(share): simplify ddev share provider scripts and show output in real-time - #8156

Merged
rfay merged 6 commits into
ddev:mainfrom
stasadev:20260218_stasadev_share
Feb 19, 2026
Merged

rfay merged 6 commits into
ddev:mainfrom
stasadev:20260218_stasadev_share

Conversation

@stasadev

Copy link
Copy Markdown
Member

The Issue

From Discord https://discord.com/channels/664580571770388500/1473660992369197127

This previously worked but no longer does and just wondering if anything has changed? The provider script is ddev generated and not changed, removing and restarting doesnt resolve the issue.

~/Projects/test (redacted ✗) ddev share
Using share provider script: /Users/josh/Projects/test/.ddev/share-providers/ngrok.sh 
Sharing http://127.0.0.1:33038 
Tunnel URL: https://redacted.ngrok-free.dev 
Provider 'ngrok' exited with code 1 
Provider stderr output:
Running: ngrok http http://127.0.0.1:33038 
Starting ngrok tunnel...

It is impossible to understand what is going on here without manually running ngrok http http://127.0.0.1:33038


I see the same situation with Cloudflared:

When ddev share --provider=cloudflared failed, users saw only "Provider 'cloudflared' did not output a URL" with no error details. The actual error (e.g., "context deadline exceeded") was silently swallowed, forcing users to manually run the cloudflared command to diagnose the problem. Two bugs caused this:

  1. set -e caused scripts to abort at wait $PID before reaching diagnostic output code
  2. Stderr filtering suppressed non-structured error messages

How This PR Solves The Issue

Rewrites all three share provider scripts (cloudflared, ngrok, localtunnel) to follow the same simple pattern:

  • cmd 2>&1 | while IFS= read -r line replaces named pipes, temp files, background readers, and polling loops
  • All provider output is shown to the user in real-time via stderr
  • Only structured INFO lines are filtered (INF for cloudflared, lvl=info for ngrok); errors always show
  • URL is extracted from output with provider-specific regex and sent to stdout for DDEV to capture
  • ngrok now uses --log=stdout and parses the URL from log output instead of polling the localhost:4040 API (removes curl/jq dep)

Go-side changes (share.go):

  • Removed stderr pipe/buffer machinery; stderr goes directly to os.Stderr since scripts now handle output display
  • Removed verbose stdout branching (scripts show everything on stderr)
  • Added 60-second timeout for URL capture as a safety net
  • Provider exit code is now propagated to the ddev process

Other improvements:

  • PopulateShareProviders() is called from GetShareProviderScript() so script updates take effect on ddev share without requiring ddev restart
  • localtunnel example fetches and displays the tunnel password
  • Added ddev-generated customization note to localtunnel example

Manual Testing Instructions

  1. Run ddev share --provider=ngrok - verify tunnel starts, URL is displayed, and non-info log output is visible
  2. Run ddev share --provider=cloudflared - verify tunnel starts, URL is displayed, and non-info log output is visible
  3. Test localtunnel: cp .ddev/share-providers/localtunnel.sh.example .ddev/share-providers/localtunnel.sh && ddev share --provider=localtunnel
  4. Test without internet connectivity - verify error output is shown in real-time rather than silently swallowed
  5. Run two ddev share --provider=ngrok for the same project - verify the second instance shows a clear error

Automated Testing Overview

Release/Deployment Notes

@stasadev
stasadev requested a review from a team as a code owner February 18, 2026 15:43
@github-actions

github-actions Bot commented Feb 18, 2026 •

Copy link
Copy Markdown

@stasadev

Copy link
Copy Markdown
Member Author

Note: it's important to run ddev restart or ddev config --auto in DDEV HEAD, if you test ddev share after using binary from this PR, because files inside .ddev/share-providers are not updated automatically when you run ddev share.

No internet ngrok:

Before (no error details):

$ ddev share --provider=ngrok
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/ngrok.sh 
Sharing http://127.0.0.1:32872 
Provider stderr output:
Running: ngrok http http://127.0.0.1:32872 
Starting ngrok tunnel...
Error: Failed to get ngrok URL after 30 seconds
 
Provider 'ngrok' did not output a URL

After:

$ ddev share --provider=ngrok
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/ngrok.sh 
Sharing http://127.0.0.1:32864 
Starting ngrok tunnel...

Running command: ngrok http http://127.0.0.1:32864 --log=stdout 

t=2026-02-18T17:53:39+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:53:39+0200 lvl=warn msg="failed to check for update" obj=updater err="Post \"https://update.ngrok-agent.com/check\": dial tcp: lookup update.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:53:40+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:53:41+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:53:43+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:53:47+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:53:55+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
t=2026-02-18T17:54:11+0200 lvl=eror msg="failed to reconnect session" obj=tunnels.session err="failed to dial ngrok server with address \"connect.us.ngrok-agent.com:443\": dial tcp: lookup connect.us.ngrok-agent.com on 127.0.0.1:53: server misbehaving"
Provider 'ngrok' did not output a URL within 60 seconds

No internet cloudflared:

Before (no error details):

$ ddev share --provider=cloudflared
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/cloudflared.sh 
Sharing http://127.0.0.1:32872 
Provider stderr output:
Starting cloudflared tunnel...
Running: cloudflared tunnel --url http://127.0.0.1:32872 --protocol http2 
 
Provider 'cloudflared' did not output a URL

After:

$ ddev share --provider=cloudflared
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/cloudflared.sh 
Sharing http://127.0.0.1:32864 
Starting cloudflared tunnel...

Running command: cloudflared tunnel --url http://127.0.0.1:32864 --protocol http2 

failed to request quick Tunnel: Post "https://api.trycloudflare.com/tunnel": dial tcp: lookup api.trycloudflare.com on 127.0.0.1:53: server misbehaving
Provider 'cloudflared' did not output a URL

No internet localtunnel:

Before (no error details):

$ cp .ddev/share-providers/localtunnel.sh.example .ddev/share-providers/localtunnel.sh
$ ddev share --provider=localtunnel
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/localtunnel.sh 
Sharing http://127.0.0.1:32872 
Provider stderr output:
Starting localtunnel on port 32872...
Error: Failed to get localtunnel URL after 30 seconds
 
Provider 'localtunnel' did not output a URL

After (the same, but this is how localtunnel works, it doesn't output any errors here):

$ cp .ddev/share-providers/localtunnel.sh.example .ddev/share-providers/localtunnel.sh
$ ddev share --provider=localtunnel
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/localtunnel.sh 
Sharing http://127.0.0.1:32864 
Starting localtunnel...

Running command: lt --port 32864 

Provider 'localtunnel' did not output a URL within 60 seconds

My local problems with cloudflared (it's blocked on internet provider level):

Before (no error details):

$ ddev share --provider=cloudflared
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/cloudflared.sh 
Sharing http://127.0.0.1:32880 
Provider stderr output:
Starting cloudflared tunnel...
Running: cloudflared tunnel --url http://127.0.0.1:32880 --protocol http2 
 
Provider 'cloudflared' did not output a URL

After:

$ ddev share --provider=cloudflared
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/cloudflared.sh 
Sharing http://127.0.0.1:32864 
Starting cloudflared tunnel...

Running command: cloudflared tunnel --url http://127.0.0.1:32864 --protocol http2 

failed to request quick Tunnel: Post "https://api.trycloudflare.com/tunnel": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Provider 'cloudflared' did not output a URL

My another local problem with cloudflared, when I try to connect to cloudflare network using Cloudflare WARP:

You've requested a page on a website (anyone-musical-republic-mild.trycloudflare.com) that is on the Cloudflare network. Unfortunately, it is resolving to an IP address that is creating a conflict within Cloudflare's system.

Before (no errors for failed incoming requests):

$ ddev share --provider=cloudflared
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/cloudflared.sh 
Sharing http://127.0.0.1:32872 
Tunnel URL: https://participate-drive-washington-basically.trycloudflare.com
# (no errors for failed incoming requests)

After:

$ ddev share --provider=cloudflared
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/cloudflared.sh 
Sharing http://127.0.0.1:32864 
Starting cloudflared tunnel...

Running command: cloudflared tunnel --url http://127.0.0.1:32864 --protocol http2 

Tunnel URL: https://anyone-musical-republic-mild.trycloudflare.com 
2026-02-18T16:11:09Z ERR  error="Incoming request ended abruptly: context canceled" connIndex=0 event=1 ingressRule=0 originService=http://127.0.0.1:32864
2026-02-18T16:11:09Z ERR failed to serve incoming request error="Failed to proxy HTTP: Incoming request ended abruptly: context canceled"

Improvement in localtunnel:

Before (no password info):

$ cp .ddev/share-providers/localtunnel.sh.example .ddev/share-providers/localtunnel.sh
$ ddev share --provider=localtunnel
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/localtunnel.sh 
Sharing http://127.0.0.1:32872 
Tunnel URL: https://few-memes-rescue.loca.lt

After (now with a password):

$ cp .ddev/share-providers/localtunnel.sh.example .ddev/share-providers/localtunnel.sh
$ ddev share --provider=localtunnel
Using share provider script: /home/stas/code/ddev/ddev.com/.ddev/share-providers/localtunnel.sh 
Sharing http://127.0.0.1:32864 
Starting localtunnel...

Running command: lt --port 32864 

Tunnel URL: https://bitter-papers-move.loca.lt 
your password is: <my-ip>
your url is: https://bitter-papers-move.loca.lt

@stasadev
stasadev force-pushed the 20260218_stasadev_share branch from 2f40bbe to de7f3cd Compare February 18, 2026 16:38
@stasadev

Copy link
Copy Markdown
Member Author

TODO: test how it works on traditional Windows without the Internet. When a script reaches a timeout of 60 seconds, it must terminate not only the script process, but also the child process ngrok.

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks to me like an excellent simplification and it's way better to show error output. Thanks!

# Documentation: https://docs.ddev.com/en/stable/users/topics/sharing/
#
# To customize: remove the '#ddev-generated' line above and edit as needed.
# To customize: remove the 'ddev-generated' line above and edit as needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch :)

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It works great, and is a major improvement.

But it doesn't work at all on WIndows, hopefully fixed in

But when that goes in, this one will have to be checked to see if post-share hook gets properly handled on ngrok.

stasadev and others added 3 commits February 19, 2026 13:16
## The Issue

When `ddev share --provider=cloudflared` failed, users saw only
"Provider 'cloudflared' did not output a URL" with no error details.
The actual error (e.g., "context deadline exceeded") was silently
swallowed, forcing users to manually run the cloudflared command to
diagnose the problem. Two bugs caused this:

1. `set -e` caused scripts to abort at `wait $PID` before reaching
   diagnostic output code
2. Stderr filtering suppressed non-structured error messages

## How This PR Solves The Issue

Rewrites all three share provider scripts (cloudflared, ngrok,
localtunnel) to follow the same simple pattern:

- `cmd 2>&1 | while IFS= read -r line` replaces named pipes, temp
  files, background readers, and polling loops
- All provider output is shown to the user in real-time via stderr
- Only structured INFO lines are filtered (` INF ` for cloudflared,
  ` lvl=info ` for ngrok); errors always show
- URL is extracted from output with provider-specific regex and sent
  to stdout for DDEV to capture
- ngrok now uses `--log=stdout` and parses the URL from log output
  instead of polling the localhost:4040 API (removes curl/jq dep)

Go-side changes (share.go):
- Removed stderr pipe/buffer machinery; stderr goes directly to
  os.Stderr since scripts now handle output display
- Removed verbose stdout branching (scripts show everything on stderr)
- Added 60-second timeout for URL capture as a safety net
- Provider exit code is now propagated to the ddev process

Other improvements:
- `PopulateShareProviders()` is called from `GetShareProviderScript()`
  so script updates take effect on `ddev share` without requiring
  `ddev restart`
- localtunnel example fetches and displays the tunnel password
- Added ddev-generated customization note to localtunnel example

## Manual Testing Instructions

1. Run `ddev share --provider=ngrok` - verify tunnel starts, URL is
   displayed, and non-info log output is visible
2. Run `ddev share --provider=cloudflared` - verify tunnel starts,
   URL is displayed, and non-info log output is visible
3. Test localtunnel:
   `cp .ddev/share-providers/localtunnel.sh.example .ddev/share-providers/localtunnel.sh && ddev share --provider=localtunnel`
4. Test without internet connectivity - verify error output is shown
   in real-time rather than silently swallowed
5. Run two `ddev share --provider=ngrok` for the same project - verify
   the second instance shows a clear error

## Automated Testing Overview

No new automated tests. The share providers require external services
(ngrok, cloudflared) that are not available in CI. Changes are
tested manually.

## Release/Deployment Notes

- ngrok share provider now requires ngrok to support `--log=stdout`
  flag (available in all current versions)
- The localhost:4040 API polling approach for ngrok is removed
- Share provider scripts will auto-update on next `ddev share` (via
  PopulateShareProviders) for projects with #ddev-generated scripts

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@stasadev
stasadev force-pushed the 20260218_stasadev_share branch from de7f3cd to a11d4a0 Compare February 19, 2026 11:20
@stasadev

Copy link
Copy Markdown
Member Author

TODO: test how it works on traditional Windows without the Internet. When a script reaches a timeout of 60 seconds, it must terminate not only the script process, but also the child process ngrok.

I retested it, and all processes are terminated correctly.

this one will have to be checked to see if post-share hook gets properly handled on ngrok

ngrok works fine for me with both pre-share and post-share hooks.

@stasadev
stasadev requested a review from rfay February 19, 2026 11:47

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like everyhing is great now, including Windows!

@rfay
rfay merged commit f8e24e3 into ddev:main Feb 19, 2026
2 checks passed
@rfay
rfay deleted the 20260218_stasadev_share branch February 19, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants