Skip to content

Commit 09ca65a

Browse files
committed
Merge branch 'main' into 3522-autogenerate-docs-2
2 parents f4349e1 + 50d1c71 commit 09ca65a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1409
-968
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Large diffs are not rendered by default.

agent/agent.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,16 @@ func (a *agent) run(ctx context.Context) error {
215215
return xerrors.Errorf("create tailnet: %w", err)
216216
}
217217
a.closeMutex.Lock()
218-
a.network = network
218+
// Re-check if agent was closed while initializing the network.
219+
closed := a.isClosed()
220+
if !closed {
221+
a.network = network
222+
}
219223
a.closeMutex.Unlock()
224+
if closed {
225+
_ = network.Close()
226+
return xerrors.New("agent is closed")
227+
}
220228
} else {
221229
// Update the DERP map!
222230
network.SetDERPMap(metadata.DERPMap)
@@ -246,27 +254,20 @@ func (a *agent) trackConnGoroutine(fn func()) error {
246254
}
247255

248256
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_ *tailnet.Conn, err error) {
249-
a.closeMutex.Lock()
250-
if a.isClosed() {
251-
a.closeMutex.Unlock()
252-
return nil, xerrors.New("closed")
253-
}
254257
network, err := tailnet.NewConn(&tailnet.Options{
255258
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.TailnetIP, 128)},
256259
DERPMap: derpMap,
257260
Logger: a.logger.Named("tailnet"),
258261
EnableTrafficStats: true,
259262
})
260263
if err != nil {
261-
a.closeMutex.Unlock()
262264
return nil, xerrors.Errorf("create tailnet: %w", err)
263265
}
264266
defer func() {
265267
if err != nil {
266268
network.Close()
267269
}
268270
}()
269-
a.closeMutex.Unlock()
270271

271272
sshListener, err := network.Listen("tcp", ":"+strconv.Itoa(codersdk.TailnetSSHPort))
272273
if err != nil {

0 commit comments

Comments
 (0)