From 4ce7e1eed00eca3f3344808160b59e366356a05c Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 21 Aug 2024 23:57:53 +0300 Subject: [PATCH 1/3] add new values for keepalive --- internal/build/agent.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/build/agent.go b/internal/build/agent.go index a4d0a3b..5f7887b 100644 --- a/internal/build/agent.go +++ b/internal/build/agent.go @@ -4,9 +4,11 @@ import ( "context" "net" "strconv" + "time" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/keepalive" "github.com/bavix/vakeel-way/pkg/api/vakeel_way" "github.com/bavix/vakeel/internal/app" @@ -14,6 +16,16 @@ import ( "github.com/bavix/vakeel/pkg/ctxid" ) +// Keep-alive parameters for the gRPC client. +// The client will send a ping to the server every 10 seconds if there is no activity. +// The client will consider the connection dead if it doesn't receive a pong within 1 second. +// The client will allow the connection to be established without a stream. +const ( + keepAliveTime = 10 * time.Second // The time between pings. + keepAliveTimeout = 1 * time.Second // The time to wait for a pong. + allowWithoutStreams = true // Allow the connection to be established without a stream. +) + // AgentApp creates a gRPC client and connects to the server's update service. // It returns an error if the connection or the update service call fails. // @@ -21,9 +33,18 @@ import ( // Returns: An error if the connection or update service call fails. func (b *Builder) AgentApp(ctx context.Context) error { // Create a gRPC client insecure connection to the server. + // The connection is established using the host and port from the configuration. + // The connection is configured with keep-alive parameters to send pings to the server + // every 10 seconds if there is no activity and to consider the connection dead if + // a ping ack is not received within 1 second. conn, err := grpc.NewClient( net.JoinHostPort(b.config.Host, strconv.Itoa(b.config.Port)), grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithKeepaliveParams(keepalive.ClientParameters{ + Time: keepAliveTime, + Timeout: keepAliveTimeout, + PermitWithoutStream: allowWithoutStreams, + }), ) if err != nil { return err @@ -32,8 +53,12 @@ func (b *Builder) AgentApp(ctx context.Context) error { // Close the connection when the function returns. defer conn.Close() + // Create a client for the vakeel_way.StateService. serviceClient := vakeel_way.NewStateServiceClient(conn) + // Call the app.Agent function to start the agent. + // The agent sends update requests to the server using the client stream. + // The function returns an error if sending the update request fails. return app.Agent(ctx, serviceClient) } From a45e835d0b9562c2924b138eb89fe7d0f4607639 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 22 Aug 2024 00:01:04 +0300 Subject: [PATCH 2/3] go1.23 --- .github/workflows/golangci-lint.yml | 4 ++-- .github/workflows/unit.yml | 2 +- .golangci.yml | 1 + Makefile | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index facb82e..a84a071 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ '1.22' ] + go-version: [ '1.23' ] steps: - uses: actions/checkout@v4 - name: Setup Go @@ -23,4 +23,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.59.1 + version: v1.60.1 diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 3a20294..26c3b25 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ '1.22' ] + go-version: [ '1.23' ] steps: - uses: actions/checkout@v4 - name: Setup Go diff --git a/.golangci.yml b/.golangci.yml index 300eed7..5714315 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,5 @@ run: + go: "1.23" timeout: 1m linters: enable-all: true diff --git a/Makefile b/Makefile index 66b6495..0489f3b 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ test: go test -tags mock -race -cover ./... lint: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run --color always ${args} + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 run --color always ${args} lint-fix: make lint args=--fix From e1ba59f807eb762580bce5fb83969ceb574dbe50 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 22 Aug 2024 00:01:33 +0300 Subject: [PATCH 3/3] go1.23 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9957932..741a632 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bavix/vakeel -go 1.22.5 +go 1.23 require ( github.com/bavix/apis v1.0.0