Skip to content

fix: Tidy up closes for nicer output #4605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ func (h *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) {

// ExperimentalEnabled returns if the experimental feature flag is enabled.
func ExperimentalEnabled(cmd *cobra.Command) bool {
return cliflag.IsSetBool(cmd, varExperimental)
enabled, _ := cmd.Flags().GetBool(varExperimental)
return enabled
}

// EnsureExperimental will ensure that the experimental feature flag is set if the given flag is set.
Expand Down
7 changes: 3 additions & 4 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,13 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
), dflags.PromAddress.Value, "prometheus")()
}

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

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

cmd.Println("Waiting for WebSocket connections to close...")
_ = coderAPI.Close()
_ = coderAPICloser.Close()
cmd.Println("Done waiting for WebSocket connections")

// Close tunnel after we no longer have in-flight connections.
Expand Down
4 changes: 0 additions & 4 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions coderd/database/migrations/000059_file_id.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ BEGIN;
-- Drop the primary key on hash.
ALTER TABLE files DROP CONSTRAINT files_pkey;

-- This extension is required by gen_random_uuid
CREATE EXTENSION IF NOT EXISTS pgcrypto;

-- Add an 'id' column and designate it the primary key.
ALTER TABLE files ADD COLUMN
id uuid NOT NULL PRIMARY KEY DEFAULT gen_random_uuid ();
Expand Down
4 changes: 4 additions & 0 deletions coderd/tracing/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tracing
import (
"context"

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

tracerProvider := sdktrace.NewTracerProvider(tracerOpts...)
otel.SetTracerProvider(tracerProvider)
// Ignore otel errors!
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

otel.SetTextMapPropagator(
propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
),
)
otel.SetLogger(logr.Discard())

return tracerProvider, func(ctx context.Context) error {
for _, close := range closers {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/tailnet/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (c *haCoordinator) ServeAgent(conn net.Conn, id uuid.UUID) error {
for {
node, err := c.handleAgentUpdate(id, decoder)
if err != nil {
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrClosedPipe) {
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrClosedPipe) || errors.Is(err, context.Canceled) {
return nil
}
return xerrors.Errorf("handle next agent message: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion tailnet/coordinator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tailnet

import (
"context"
"encoding/json"
"errors"
"io"
Expand Down Expand Up @@ -289,7 +290,7 @@ func (c *coordinator) ServeAgent(conn net.Conn, id uuid.UUID) error {
for {
err := c.handleNextAgentMessage(id, decoder)
if err != nil {
if errors.Is(err, io.EOF) {
if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {
return nil
}
return xerrors.Errorf("handle next agent message: %w", err)
Expand Down