@@ -221,12 +221,18 @@ func (a *agent) run(ctx context.Context) error {
221
221
}
222
222
223
223
func (a * agent ) createTailnet (ctx context.Context , derpMap * tailcfg.DERPMap ) (* tailnet.Conn , error ) {
224
+ a .closeMutex .Lock ()
225
+ if a .isClosed () {
226
+ a .closeMutex .Unlock ()
227
+ return nil , xerrors .New ("closed" )
228
+ }
224
229
network , err := tailnet .NewConn (& tailnet.Options {
225
230
Addresses : []netip.Prefix {netip .PrefixFrom (codersdk .TailnetIP , 128 )},
226
231
DERPMap : derpMap ,
227
232
Logger : a .logger .Named ("tailnet" ),
228
233
})
229
234
if err != nil {
235
+ a .closeMutex .Unlock ()
230
236
return nil , xerrors .Errorf ("create tailnet: %w" , err )
231
237
}
232
238
a .network = network
@@ -237,14 +243,13 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
237
243
}
238
244
return a .stats .wrapConn (conn )
239
245
})
246
+ a .connCloseWait .Add (4 )
247
+ a .closeMutex .Unlock ()
240
248
241
249
sshListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .TailnetSSHPort ))
242
250
if err != nil {
243
251
return nil , xerrors .Errorf ("listen on the ssh port: %w" , err )
244
252
}
245
- a .closeMutex .Lock ()
246
- a .connCloseWait .Add (1 )
247
- a .closeMutex .Unlock ()
248
253
go func () {
249
254
defer a .connCloseWait .Done ()
250
255
for {
@@ -260,9 +265,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
260
265
if err != nil {
261
266
return nil , xerrors .Errorf ("listen for reconnecting pty: %w" , err )
262
267
}
263
- a .closeMutex .Lock ()
264
- a .connCloseWait .Add (1 )
265
- a .closeMutex .Unlock ()
266
268
go func () {
267
269
defer a .connCloseWait .Done ()
268
270
for {
@@ -298,9 +300,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
298
300
if err != nil {
299
301
return nil , xerrors .Errorf ("listen for speedtest: %w" , err )
300
302
}
301
- a .closeMutex .Lock ()
302
- a .connCloseWait .Add (1 )
303
- a .closeMutex .Unlock ()
304
303
go func () {
305
304
defer a .connCloseWait .Done ()
306
305
for {
@@ -323,9 +322,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
323
322
if err != nil {
324
323
return nil , xerrors .Errorf ("listen for statistics: %w" , err )
325
324
}
326
- a .closeMutex .Lock ()
327
- a .connCloseWait .Add (1 )
328
- a .closeMutex .Unlock ()
329
325
go func () {
330
326
defer a .connCloseWait .Done ()
331
327
defer statisticsListener .Close ()
@@ -569,7 +565,6 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
569
565
// Set environment variables reliable detection of being inside a
570
566
// Coder workspace.
571
567
cmd .Env = append (cmd .Env , "CODER=true" )
572
-
573
568
cmd .Env = append (cmd .Env , fmt .Sprintf ("USER=%s" , username ))
574
569
// Git on Windows resolves with UNIX-style paths.
575
570
// If using backslashes, it's unable to find the executable.
@@ -585,6 +580,10 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
585
580
cmd .Env = append (cmd .Env , fmt .Sprintf ("SSH_CLIENT=%s %s %s" , srcAddr , srcPort , dstPort ))
586
581
cmd .Env = append (cmd .Env , fmt .Sprintf ("SSH_CONNECTION=%s %s %s %s" , srcAddr , srcPort , dstAddr , dstPort ))
587
582
583
+ // This adds the ports dialog to code-server that enables
584
+ // proxying a port dynamically.
585
+ cmd .Env = append (cmd .Env , fmt .Sprintf ("VSCODE_PROXY_URI=%s" , metadata .VSCodePortProxyURI ))
586
+
588
587
// Hide Coder message on code-server's "Getting Started" page
589
588
cmd .Env = append (cmd .Env , "CS_DISABLE_GETTING_STARTED_OVERRIDE=true" )
590
589
0 commit comments