Skip to content

Commit c5afaff

Browse files
authored
fix: Tidy up closes for nicer output (#4605)
* fix: Tidy up closes for nicer output There was a context canceled message that would appear because of traces, and this was using the wrong close. I don't think it was causing any specific problems, but it could make a replica warning appear on restart. * Fix migration and experimental
1 parent e0a14f6 commit c5afaff

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

cli/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ func (h *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) {
609609

610610
// ExperimentalEnabled returns if the experimental feature flag is enabled.
611611
func ExperimentalEnabled(cmd *cobra.Command) bool {
612-
return cliflag.IsSetBool(cmd, varExperimental)
612+
enabled, _ := cmd.Flags().GetBool(varExperimental)
613+
return enabled
613614
}
614615

615616
// EnsureExperimental will ensure that the experimental feature flag is set if the given flag is set.

cli/server.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,13 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
476476
), dflags.PromAddress.Value, "prometheus")()
477477
}
478478

479-
// We use a separate closer so the Enterprise API
479+
// We use a separate coderAPICloser so the Enterprise API
480480
// can have it's own close functions. This is cleaner
481481
// than abstracting the Coder API itself.
482-
coderAPI, closer, err := newAPI(ctx, options)
482+
coderAPI, coderAPICloser, err := newAPI(ctx, options)
483483
if err != nil {
484484
return err
485485
}
486-
defer closer.Close()
487486

488487
client := codersdk.New(localURL)
489488
if dflags.TLSEnable.Value {
@@ -663,7 +662,7 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
663662
wg.Wait()
664663

665664
cmd.Println("Waiting for WebSocket connections to close...")
666-
_ = coderAPI.Close()
665+
_ = coderAPICloser.Close()
667666
cmd.Println("Done waiting for WebSocket connections")
668667

669668
// Close tunnel after we no longer have in-flight connections.

coderd/database/dump.sql

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000059_file_id.up.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ BEGIN;
1414
-- Drop the primary key on hash.
1515
ALTER TABLE files DROP CONSTRAINT files_pkey;
1616

17-
-- This extension is required by gen_random_uuid
18-
CREATE EXTENSION IF NOT EXISTS pgcrypto;
19-
2017
-- Add an 'id' column and designate it the primary key.
2118
ALTER TABLE files ADD COLUMN
2219
id uuid NOT NULL PRIMARY KEY DEFAULT gen_random_uuid ();

coderd/tracing/exporter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tracing
33
import (
44
"context"
55

6+
"github.com/go-logr/logr"
67
"go.opentelemetry.io/otel"
78
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
89
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
@@ -59,12 +60,15 @@ func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdkt
5960

6061
tracerProvider := sdktrace.NewTracerProvider(tracerOpts...)
6162
otel.SetTracerProvider(tracerProvider)
63+
// Ignore otel errors!
64+
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {}))
6265
otel.SetTextMapPropagator(
6366
propagation.NewCompositeTextMapPropagator(
6467
propagation.TraceContext{},
6568
propagation.Baggage{},
6669
),
6770
)
71+
otel.SetLogger(logr.Discard())
6872

6973
return tracerProvider, func(ctx context.Context) error {
7074
for _, close := range closers {

enterprise/tailnet/coordinator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (c *haCoordinator) ServeAgent(conn net.Conn, id uuid.UUID) error {
215215
for {
216216
node, err := c.handleAgentUpdate(id, decoder)
217217
if err != nil {
218-
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrClosedPipe) {
218+
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrClosedPipe) || errors.Is(err, context.Canceled) {
219219
return nil
220220
}
221221
return xerrors.Errorf("handle next agent message: %w", err)

tailnet/coordinator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tailnet
22

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"io"
@@ -289,7 +290,7 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID) error {
289290
for {
290291
err := c.handleNextAgentMessage(id, decoder)
291292
if err != nil {
292-
if errors.Is(err, io.EOF) {
293+
if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {
293294
return nil
294295
}
295296
return xerrors.Errorf("handle next agent message: %w", err)

0 commit comments

Comments
 (0)