Skip to content

Commit 6313e48

Browse files
authored
CloseConnection doesn't return error (#131)
1 parent c2c1f89 commit 6313e48

File tree

11 files changed

+60
-70
lines changed

11 files changed

+60
-70
lines changed

client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ type (
350350
DescribeTaskList(ctx context.Context, tasklist string, tasklistType tasklistpb.TaskListType) (*workflowservice.DescribeTaskListResponse, error)
351351

352352
// CloseConnection closes underlying gRPC connection.
353-
CloseConnection() error
353+
CloseConnection()
354354
}
355355

356356
// NamespaceClient is the client for managing operations on the namespace.
@@ -381,7 +381,7 @@ type (
381381
Update(ctx context.Context, request *workflowservice.UpdateNamespaceRequest) error
382382

383383
// CloseConnection closes underlying gRPC connection.
384-
CloseConnection() error
384+
CloseConnection()
385385
}
386386
)
387387

internal/client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ type (
313313
DescribeTaskList(ctx context.Context, tasklist string, tasklistType tasklistpb.TaskListType) (*workflowservice.DescribeTaskListResponse, error)
314314

315315
// CloseConnection closes underlying gRPC connection.
316-
CloseConnection() error
316+
CloseConnection()
317317
}
318318

319319
// ClientOptions are optional parameters for Client creation.
@@ -327,6 +327,10 @@ type (
327327
// default: default
328328
Namespace string
329329

330+
// Optional: Logger framework can use to log.
331+
// default: default logger provided.
332+
Logger *zap.Logger
333+
330334
// Optional: Metrics to be reported.
331335
// Default metrics are Prometheus compatible but default separator (.) should be replaced with some other character:
332336
// opts := tally.ScopeOptions{
@@ -510,7 +514,7 @@ type (
510514
Update(ctx context.Context, request *workflowservice.UpdateNamespaceRequest) error
511515

512516
// CloseConnection closes underlying gRPC connection.
513-
CloseConnection() error
517+
CloseConnection()
514518
}
515519

516520
// WorkflowIDReusePolicy defines workflow ID reuse behavior.
@@ -600,6 +604,7 @@ func NewServiceClient(workflowServiceClient workflowservice.WorkflowServiceClien
600604
namespace: options.Namespace,
601605
registry: newRegistry(),
602606
metricsScope: metrics.NewTaggedScope(options.MetricsScope),
607+
logger: options.Logger,
603608
identity: options.Identity,
604609
dataConverter: options.DataConverter,
605610
contextPropagators: options.ContextPropagators,
@@ -632,6 +637,7 @@ func newNamespaceServiceClient(workflowServiceClient workflowservice.WorkflowSer
632637
workflowService: workflowServiceClient,
633638
connectionCloser: clientConn,
634639
metricsScope: options.MetricsScope,
640+
logger: options.Logger,
635641
identity: options.Identity,
636642
}
637643
}

internal/internal_worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ func NewAggregatedWorker(client *WorkflowClient, taskList string, options Worker
13421342
MaxConcurrentDecisionPollers: options.MaxConcurrentDecisionTaskPollers,
13431343
Identity: client.identity,
13441344
MetricsScope: client.metricsScope,
1345-
Logger: options.Logger,
1345+
Logger: client.logger,
13461346
EnableLoggingInReplay: options.EnableLoggingInReplay,
13471347
UserContext: backgroundActivityContext,
13481348
UserContextCancel: backgroundActivityContextCancel,

internal/internal_worker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ func TestWorkerOptionNonDefaults(t *testing.T) {
14581458
dataConverter: &defaultDataConverter{},
14591459
contextPropagators: nil,
14601460
tracer: nil,
1461+
logger: zap.NewNop(),
14611462
}
14621463

14631464
options := WorkerOptions{
@@ -1473,7 +1474,6 @@ func TestWorkerOptionNonDefaults(t *testing.T) {
14731474
WorkerActivitiesPerSecond: 99,
14741475
StickyScheduleToStartTimeout: 555 * time.Minute,
14751476
BackgroundActivityContext: context.Background(),
1476-
Logger: zap.NewNop(),
14771477
}
14781478

14791479
aggWorker := NewAggregatedWorker(client, taskList, options)
@@ -1495,7 +1495,7 @@ func TestWorkerOptionNonDefaults(t *testing.T) {
14951495
StickyScheduleToStartTimeout: options.StickyScheduleToStartTimeout,
14961496
DataConverter: client.dataConverter,
14971497
Tracer: client.tracer,
1498-
Logger: options.Logger,
1498+
Logger: client.logger,
14991499
MetricsScope: client.metricsScope,
15001500
Identity: client.identity,
15011501
}

internal/internal_workers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ func (s *WorkersTestSuite) TestLongRunningDecisionTask() {
327327
}).Times(2)
328328

329329
options := WorkerOptions{
330-
Logger: zap.NewNop(),
331330
DisableActivityWorker: true,
332331
}
333332
clientOptions := ClientOptions{
333+
Logger: zap.NewNop(),
334334
Identity: "test-worker-identity",
335335
}
336336

@@ -460,10 +460,10 @@ func (s *WorkersTestSuite) TestMultipleLocalActivities() {
460460
}).Times(1)
461461

462462
options := WorkerOptions{
463-
Logger: zap.NewNop(),
464463
DisableActivityWorker: true,
465464
}
466465
clientOptions := ClientOptions{
466+
Logger: zap.NewNop(),
467467
Identity: "test-worker-identity",
468468
}
469469

internal/internal_workflow_client.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/opentracing/opentracing-go"
3636
"github.com/pborman/uuid"
3737
"github.com/uber-go/tally"
38+
"go.uber.org/zap"
3839

3940
commonpb "go.temporal.io/temporal-proto/common"
4041
eventpb "go.temporal.io/temporal-proto/event"
@@ -70,6 +71,7 @@ type (
7071
connectionCloser io.Closer
7172
namespace string
7273
registry *registry
74+
logger *zap.Logger
7375
metricsScope *metrics.TaggedScope
7476
identity string
7577
dataConverter DataConverter
@@ -82,6 +84,7 @@ type (
8284
workflowService workflowservice.WorkflowServiceClient
8385
connectionCloser io.Closer
8486
metricsScope tally.Scope
87+
logger *zap.Logger
8588
identity string
8689
}
8790

@@ -942,12 +945,13 @@ func (wc *WorkflowClient) DescribeTaskList(ctx context.Context, taskList string,
942945
}
943946

944947
// CloseConnection closes underlying gRPC connection.
945-
func (wc *WorkflowClient) CloseConnection() error {
948+
func (wc *WorkflowClient) CloseConnection() {
946949
if wc.connectionCloser == nil {
947-
return nil
950+
return
951+
}
952+
if err := wc.connectionCloser.Close(); err != nil {
953+
wc.logger.Warn("unable to close connection", zap.Error(err))
948954
}
949-
950-
return wc.connectionCloser.Close()
951955
}
952956

953957
func (wc *WorkflowClient) getWorkflowHeader(ctx context.Context) *commonpb.Header {
@@ -966,13 +970,13 @@ func (wc *WorkflowClient) getWorkflowHeader(ctx context.Context) *commonpb.Heade
966970
// - NamespaceAlreadyExistsError
967971
// - BadRequestError
968972
// - InternalServiceError
969-
func (dc *namespaceClient) Register(ctx context.Context, request *workflowservice.RegisterNamespaceRequest) error {
973+
func (nc *namespaceClient) Register(ctx context.Context, request *workflowservice.RegisterNamespaceRequest) error {
970974
return backoff.Retry(ctx,
971975
func() error {
972976
tchCtx, cancel := newChannelContext(ctx)
973977
defer cancel()
974978
var err error
975-
_, err = dc.workflowService.RegisterNamespace(tchCtx, request)
979+
_, err = nc.workflowService.RegisterNamespace(tchCtx, request)
976980
return err
977981
}, createDynamicServiceRetryPolicy(ctx), isServiceTransientError)
978982
}
@@ -985,7 +989,7 @@ func (dc *namespaceClient) Register(ctx context.Context, request *workflowservic
985989
// - EntityNotExistsError
986990
// - BadRequestError
987991
// - InternalServiceError
988-
func (dc *namespaceClient) Describe(ctx context.Context, name string) (*workflowservice.DescribeNamespaceResponse, error) {
992+
func (nc *namespaceClient) Describe(ctx context.Context, name string) (*workflowservice.DescribeNamespaceResponse, error) {
989993
request := &workflowservice.DescribeNamespaceRequest{
990994
Name: name,
991995
}
@@ -996,7 +1000,7 @@ func (dc *namespaceClient) Describe(ctx context.Context, name string) (*workflow
9961000
tchCtx, cancel := newChannelContext(ctx)
9971001
defer cancel()
9981002
var err error
999-
response, err = dc.workflowService.DescribeNamespace(tchCtx, request)
1003+
response, err = nc.workflowService.DescribeNamespace(tchCtx, request)
10001004
return err
10011005
}, createDynamicServiceRetryPolicy(ctx), isServiceTransientError)
10021006
if err != nil {
@@ -1010,23 +1014,24 @@ func (dc *namespaceClient) Describe(ctx context.Context, name string) (*workflow
10101014
// - EntityNotExistsError
10111015
// - BadRequestError
10121016
// - InternalServiceError
1013-
func (dc *namespaceClient) Update(ctx context.Context, request *workflowservice.UpdateNamespaceRequest) error {
1017+
func (nc *namespaceClient) Update(ctx context.Context, request *workflowservice.UpdateNamespaceRequest) error {
10141018
return backoff.Retry(ctx,
10151019
func() error {
10161020
tchCtx, cancel := newChannelContext(ctx)
10171021
defer cancel()
1018-
_, err := dc.workflowService.UpdateNamespace(tchCtx, request)
1022+
_, err := nc.workflowService.UpdateNamespace(tchCtx, request)
10191023
return err
10201024
}, createDynamicServiceRetryPolicy(ctx), isServiceTransientError)
10211025
}
10221026

10231027
// CloseConnection closes underlying gRPC connection.
1024-
func (dc *namespaceClient) CloseConnection() error {
1025-
if dc.connectionCloser == nil {
1026-
return nil
1028+
func (nc *namespaceClient) CloseConnection() {
1029+
if nc.connectionCloser == nil {
1030+
return
1031+
}
1032+
if err := nc.connectionCloser.Close(); err != nil {
1033+
nc.logger.Warn("unable to close connection", zap.Error(err))
10271034
}
1028-
1029-
return dc.connectionCloser.Close()
10301035
}
10311036

10321037
func (iter *historyEventIteratorImpl) HasNext() bool {

internal/internal_workflow_testsuite.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@ import (
3333
"sync"
3434
"time"
3535

36-
decisionpb "go.temporal.io/temporal-proto/decision"
37-
tasklistpb "go.temporal.io/temporal-proto/tasklist"
38-
3936
"github.com/facebookgo/clock"
4037
"github.com/golang/mock/gomock"
4138
"github.com/opentracing/opentracing-go"
4239
"github.com/robfig/cron"
4340
"github.com/stretchr/testify/mock"
4441
"github.com/uber-go/tally"
45-
4642
commonpb "go.temporal.io/temporal-proto/common"
43+
decisionpb "go.temporal.io/temporal-proto/decision"
4744
eventpb "go.temporal.io/temporal-proto/event"
4845
executionpb "go.temporal.io/temporal-proto/execution"
4946
"go.temporal.io/temporal-proto/serviceerror"
47+
tasklistpb "go.temporal.io/temporal-proto/tasklist"
5048
"go.temporal.io/temporal-proto/workflowservice"
5149
"go.temporal.io/temporal-proto/workflowservicemock"
5250
"go.uber.org/zap"
@@ -65,9 +63,9 @@ const (
6563
workflowTypeNotSpecified = "workflow-type-not-specified"
6664

6765
// These are copied from service implementation
68-
reservedTaskListPrefix = "/__temporal_sys/"
69-
maxIDLengthLimit = 1000
70-
maxWorkflowTimeoutSeconds = 60 * 24 * 365 * 10
66+
reservedTaskListPrefix = "/__temporal_sys/"
67+
maxIDLengthLimit = 1000
68+
maxWorkflowTimeout = 24 * time.Hour * 365 * 10
7169
)
7270

7371
type (
@@ -245,7 +243,7 @@ func newTestWorkflowEnvironmentImpl(s *WorkflowTestSuite, parentRegistry *regist
245243
WorkflowType: WorkflowType{Name: workflowTypeNotSpecified},
246244
TaskListName: defaultTestTaskList,
247245

248-
WorkflowExecutionTimeoutSeconds: maxWorkflowTimeoutSeconds,
246+
WorkflowExecutionTimeoutSeconds: common.Int32Ceil(maxWorkflowTimeout.Seconds()),
249247
WorkflowTaskTimeoutSeconds: 1,
250248
},
251249
registry: r,
@@ -256,7 +254,7 @@ func newTestWorkflowEnvironmentImpl(s *WorkflowTestSuite, parentRegistry *regist
256254
doneChannel: make(chan struct{}),
257255
workerStopChannel: make(chan struct{}),
258256
dataConverter: getDefaultDataConverter(),
259-
runTimeout: maxWorkflowTimeoutSeconds * time.Second,
257+
runTimeout: maxWorkflowTimeout,
260258
}
261259

262260
// move forward the mock clock to start time.
@@ -313,10 +311,6 @@ func newTestWorkflowEnvironmentImpl(s *WorkflowTestSuite, parentRegistry *regist
313311

314312
env.service = mockService
315313

316-
if env.workerOptions.Logger == nil {
317-
env.workerOptions.Logger = env.logger
318-
}
319-
320314
return env
321315
}
322316

@@ -456,7 +450,7 @@ func (env *testWorkflowEnvironmentImpl) executeWorkflowInternal(delayStart time.
456450
wInfo.WorkflowRunTimeoutSeconds = common.Int32Ceil(env.runTimeout.Seconds())
457451
}
458452
if wInfo.WorkflowExecutionTimeoutSeconds == 0 {
459-
wInfo.WorkflowExecutionTimeoutSeconds = maxWorkflowTimeoutSeconds
453+
wInfo.WorkflowExecutionTimeoutSeconds = common.Int32Ceil(maxWorkflowTimeout.Seconds())
460454
}
461455
if wInfo.WorkflowTaskTimeoutSeconds == 0 {
462456
wInfo.WorkflowTaskTimeoutSeconds = 1
@@ -1294,7 +1288,7 @@ func (env *testWorkflowEnvironmentImpl) ExecuteLocalActivity(params executeLocal
12941288
taskHandler := localActivityTaskHandler{
12951289
userContext: env.workerOptions.BackgroundActivityContext,
12961290
metricsScope: metrics.NewTaggedScope(env.metricsScope),
1297-
logger: env.workerOptions.Logger,
1291+
logger: env.logger,
12981292
dataConverter: env.dataConverter,
12991293
tracer: env.tracer,
13001294
contextPropagators: env.contextPropagators,
@@ -1719,7 +1713,7 @@ func (env *testWorkflowEnvironmentImpl) newTestActivityTaskHandler(taskList stri
17191713
TaskList: taskList,
17201714
Identity: env.identity,
17211715
MetricsScope: env.metricsScope,
1722-
Logger: env.workerOptions.Logger,
1716+
Logger: env.logger,
17231717
UserContext: env.workerOptions.BackgroundActivityContext,
17241718
DataConverter: dataConverter,
17251719
WorkerStopChannel: env.workerStopChannel,

internal/worker.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ package internal
2727
import (
2828
"context"
2929
"time"
30-
31-
"go.uber.org/zap"
3230
)
3331

3432
type (
@@ -97,10 +95,6 @@ type (
9795
// default: 2
9896
MaxConcurrentDecisionTaskPollers int
9997

100-
// Optional: Logger framework can use to log.
101-
// default: default logger provided.
102-
Logger *zap.Logger
103-
10498
// Optional: Enable logging in replay.
10599
// In the workflow code you can use workflow.GetLogger(ctx) to write logs. By default, the logger will skip log
106100
// entry during replay mode so you won't see duplicate logs. This option will enable the logging in replay mode.

mocks/Client.go

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

mocks/NamespaceClient.go

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

0 commit comments

Comments
 (0)