Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

log/syslog: About syslog.connect() The service is abnormal due to an accidental connection failure #64165

Closed
flc1125 opened this issue Nov 15, 2023 · 2 comments

Comments

@flc1125
Copy link

flc1125 commented Nov 15, 2023

馃搶 In addition, if it is determined that this is a problem, I can submit a PR to fix it

What version of Go are you using (go version)?

$ go version

go version go1.20.2 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE="on"
GOARCH="arm64"
GOBIN="/Users/flc/go/bin"
GOCACHE="/Users/flc/Library/Caches/go-build"
GOENV="/Users/flc/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/flc/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/flc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1g/whhqsrm565v1g1r78ynk5kt00000gn/T/go-build240863129=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Recurrence situation:

I have a service, and syslog.Dial is set up before the service starts. If the syslog server is temporarily unavailable at this time, the whole service cannot be started.


see: #64168

After running TestDialWhenConnectionIsBad single measurement results

  • Before:
=== RUN   TestDialWhenConnectionIsBad
    syslog_test.go:447: syslog.Dial() failed: dial unix 127.0.0.1:12345: connect: no such file or directory
--- FAIL: TestDialWhenConnectionIsBad (0.00s)

FAIL
  • Now:
=== RUN   TestDialWhenConnectionIsBad
--- PASS: TestDialWhenConnectionIsBad (5.00s)
PASS

What did you expect to see?

I want to be able to ignore momentary disconnections without causing an exception to the primary service

What did you see instead?

Instant disconnect, just when the service is started, the service cannot be started

@seankhliao
Copy link
Member

I think this is working as intended:
given the name Dial, it is expected to actually dial the remote end like net.Dial does.
Not connecting during Dial may also mask configuration errors.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2023
@flc1125
Copy link
Author

flc1125 commented Nov 16, 2023

I think this is working as intended: given the name Dial, it is expected to actually dial the remote end like net.Dial does. Not connecting during Dial may also mask configuration errors.


Let's skip the explanation of Dial for a second. Let's look at the services provided by the syslog package. Here are a few of my examples:

package dial

import (
	"context"
	"database/sql"
	"testing"

	_ "github.com/go-sql-driver/mysql"
	"github.com/redis/go-redis/v9"
	"google.golang.org/grpc"
)

func TestMySQL(t *testing.T) {
	// This connection is invalid
	db, err := sql.Open("mysql", "username:password@tcp(hostname:port)/database_name")
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()

	// test connection
	err = db.Ping()
	if err == nil {
		t.Fatal("expected error") // <--- Success
	}
}

func TestGRPC(t *testing.T) {
	// This connection is invalid
	conn, err := grpc.Dial("hostname:port", grpc.WithInsecure())
	if err != nil {
		panic(err.Error())
	}
	defer conn.Close()

	// test invoke
	err = conn.Invoke(context.Background(), "/service_name", nil, nil)
	if err == nil {
		t.Fatal("expected error") // <--- Success
	}
}

func TestRedis(t *testing.T) {
	rdb := redis.NewClient(&redis.Options{
		Addr: "hostname:port",
	})

	// test connection
	_, err := rdb.Ping(context.Background()).Result()
	if err == nil {
		t.Fatal("expected error") // <--- Success
	}
}

The result:

=== RUN   TestMySQL
--- PASS: TestMySQL (0.03s)
=== RUN   TestGRPC
--- PASS: TestGRPC (0.00s)
=== RUN   TestRedis
--- PASS: TestRedis (0.08s)
PASS

All in: What I want to say is that as the syslog package, we should provide services and ignore the Ping part when creating the package instance. If that's true, then let's solve the Dial problem.

I'd like to hear your thoughts @seankhliao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants