Skip to content

Commit f562b74

Browse files
authored
feat: use custom wireguard reverse proxy for dev tunnel (#1975)
1 parent 71fd196 commit f562b74

File tree

5 files changed

+396
-165
lines changed

5 files changed

+396
-165
lines changed

cli/server.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"golang.org/x/mod/semver"
3434
"golang.org/x/oauth2"
3535
xgithub "golang.org/x/oauth2/github"
36+
"golang.org/x/sync/errgroup"
3637
"golang.org/x/xerrors"
3738
"google.golang.org/api/idtoken"
3839
"google.golang.org/api/option"
@@ -169,8 +170,9 @@ func server() *cobra.Command {
169170
}
170171

171172
var (
172-
tunnelErrChan <-chan error
173173
ctxTunnel, closeTunnel = context.WithCancel(cmd.Context())
174+
devTunnel = (*devtunnel.Tunnel)(nil)
175+
devTunnelErrChan = make(<-chan error, 1)
174176
)
175177
defer closeTunnel()
176178

@@ -195,10 +197,11 @@ func server() *cobra.Command {
195197
}
196198
}
197199
if err == nil {
198-
accessURL, tunnelErrChan, err = devtunnel.New(ctxTunnel, localURL)
200+
devTunnel, devTunnelErrChan, err = devtunnel.New(ctxTunnel, logger.Named("devtunnel"))
199201
if err != nil {
200202
return xerrors.Errorf("create tunnel: %w", err)
201203
}
204+
accessURL = devTunnel.URL
202205
}
203206
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
204207
}
@@ -349,7 +352,27 @@ func server() *cobra.Command {
349352
return shutdownConnsCtx
350353
},
351354
}
352-
errCh <- server.Serve(listener)
355+
356+
wg := errgroup.Group{}
357+
wg.Go(func() error {
358+
// Make sure to close the tunnel listener if we exit so the
359+
// errgroup doesn't wait forever!
360+
if dev && tunnel {
361+
defer devTunnel.Listener.Close()
362+
}
363+
364+
return server.Serve(listener)
365+
})
366+
367+
if dev && tunnel {
368+
wg.Go(func() error {
369+
defer listener.Close()
370+
371+
return server.Serve(devTunnel.Listener)
372+
})
373+
}
374+
375+
errCh <- wg.Wait()
353376
}()
354377

355378
config := createConfig(cmd)
@@ -415,7 +438,7 @@ func server() *cobra.Command {
415438
case <-cmd.Context().Done():
416439
coderAPI.Close()
417440
return cmd.Context().Err()
418-
case err := <-tunnelErrChan:
441+
case err := <-devTunnelErrChan:
419442
if err != nil {
420443
return err
421444
}
@@ -478,7 +501,7 @@ func server() *cobra.Command {
478501
if dev && tunnel {
479502
_, _ = fmt.Fprintf(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Waiting for dev tunnel to close...\n")
480503
closeTunnel()
481-
<-tunnelErrChan
504+
<-devTunnelErrChan
482505
}
483506

484507
_, _ = fmt.Fprintf(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Waiting for WebSocket connections to close...\n")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy