Skip to content

Commit 2bceb13

Browse files
authored
Fix incorrect nil handling in workflowTaskPoller (#1412)
What changed? explicit nil handling in newWorkflowTaskPoller for ldaTunnel Why? Golang doesn't handle passing in nil pointer of concrete type directly into the interface. It still considers it not nil, which will cause panic in this case. How did you test it? Unit test fail before and pass after the change
1 parent 9ffbb1f commit 2bceb13

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

internal/internal_task_pollers.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,22 @@ func newWorkflowTaskPoller(
290290
domain string,
291291
params workerExecutionParameters,
292292
) *workflowTaskPoller {
293+
/*
294+
Explicit nil handling is needed here. Otherwise, poller.ldaTunnel would not return a nil result
295+
*/
296+
var ldaTunnelInterface localDispatcher
297+
if ldaTunnel != nil {
298+
ldaTunnelInterface = ldaTunnel
299+
}
300+
293301
return &workflowTaskPoller{
294302
basePoller: basePoller{shutdownC: params.WorkerStopChannel},
295303
service: service,
296304
domain: domain,
297305
taskListName: params.TaskList,
298306
identity: params.Identity,
299307
taskHandler: taskHandler,
300-
ldaTunnel: ldaTunnel,
308+
ldaTunnel: ldaTunnelInterface,
301309
metricsScope: metrics.NewTaggedScope(params.MetricsScope),
302310
logger: params.Logger,
303311
stickyUUID: uuid.New(),

internal/internal_task_pollers_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ const (
4646
_testIdentity = "test-worker"
4747
)
4848

49+
func Test_newWorkflowTaskPoller(t *testing.T) {
50+
t.Run("success with nil ldaTunnel", func(t *testing.T) {
51+
poller := newWorkflowTaskPoller(
52+
nil,
53+
nil,
54+
nil,
55+
_testDomainName,
56+
workerExecutionParameters{})
57+
assert.NotNil(t, poller)
58+
if poller.ldaTunnel != nil {
59+
t.Error("unexpected not nil ldaTunnel")
60+
}
61+
})
62+
}
63+
4964
func TestLocalActivityPanic(t *testing.T) {
5065
// regression: panics in local activities should not terminate the process
5166
s := WorkflowTestSuite{logger: testlogger.NewZap(t)}

0 commit comments

Comments
 (0)