@@ -226,14 +226,13 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
226
226
a .closeMutex .Unlock ()
227
227
return nil , xerrors .New ("closed" )
228
228
}
229
- a .connCloseWait .Add (1 )
230
- a .closeMutex .Unlock ()
231
229
network , err := tailnet .NewConn (& tailnet.Options {
232
230
Addresses : []netip.Prefix {netip .PrefixFrom (codersdk .TailnetIP , 128 )},
233
231
DERPMap : derpMap ,
234
232
Logger : a .logger .Named ("tailnet" ),
235
233
})
236
234
if err != nil {
235
+ a .closeMutex .Unlock ()
237
236
return nil , xerrors .Errorf ("create tailnet: %w" , err )
238
237
}
239
238
a .network = network
@@ -244,6 +243,8 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
244
243
}
245
244
return a .stats .wrapConn (conn )
246
245
})
246
+ a .connCloseWait .Add (4 )
247
+ a .closeMutex .Unlock ()
247
248
248
249
sshListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .TailnetSSHPort ))
249
250
if err != nil {
@@ -264,9 +265,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
264
265
if err != nil {
265
266
return nil , xerrors .Errorf ("listen for reconnecting pty: %w" , err )
266
267
}
267
- a .closeMutex .Lock ()
268
- a .connCloseWait .Add (1 )
269
- a .closeMutex .Unlock ()
270
268
go func () {
271
269
defer a .connCloseWait .Done ()
272
270
for {
@@ -302,9 +300,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
302
300
if err != nil {
303
301
return nil , xerrors .Errorf ("listen for speedtest: %w" , err )
304
302
}
305
- a .closeMutex .Lock ()
306
- a .connCloseWait .Add (1 )
307
- a .closeMutex .Unlock ()
308
303
go func () {
309
304
defer a .connCloseWait .Done ()
310
305
for {
@@ -327,9 +322,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
327
322
if err != nil {
328
323
return nil , xerrors .Errorf ("listen for statistics: %w" , err )
329
324
}
330
- a .closeMutex .Lock ()
331
- a .connCloseWait .Add (1 )
332
- a .closeMutex .Unlock ()
333
325
go func () {
334
326
defer a .connCloseWait .Done ()
335
327
defer statisticsListener .Close ()
0 commit comments