-
Notifications
You must be signed in to change notification settings - Fork 287
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
syncer(dm): fix the data race issue #5881
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we should check a potential data race issue in such way (manually writing and reading in different routines). Perhaps just checking if the returned result is a snapshot of the original one is sufficient🤔
dm/dm/worker/subtask_test.go
Outdated
_, _ = tempQueryStatusResponse.Marshal() | ||
} | ||
}() | ||
_ = st.markResultCanceled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ = st.markResultCanceled() | |
st.markResultCanceled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked by writing and reading in different routines because in issue #4811 the data race was found in the two functions markResultCanceled() and Marshal(). So here I manually reproduce the encountered data race and fix it.
[2022-03-08T09:00:20.317Z] Write at 0x00c006394380 by goroutine 199:
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SubTask).markResultCanceled()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/subtask.go:470 +0x257
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SubTask).Pause()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/subtask.go:498 +0x54
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).OperateSubTask()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:564 +0x52c
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).operateSubTaskStage()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:743 +0x1fe
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).operateSubTaskStageWithoutConfig()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:762 +0x1b7
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).handleSubTaskStage()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:698 +0x658
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).observeSubtaskStage()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:656 +0x844
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).EnableHandleSubtasks.func1()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:438 +0x138
[2022-03-08T09:00:20.317Z]
[2022-03-08T09:00:20.317Z] Previous read at 0x00c006394380 by goroutine 289:
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/pb.(*ProcessResult).Size()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/pb/dmworker.pb.go:5308 +0x7a
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/pb.(*SubTaskStatus).Size()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/pb/dmworker.pb.go:5008 +0x34d
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/pb.(*QueryStatusResponse).Size()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/pb/dmworker.pb.go:4765 +0x1f7
[2022-03-08T09:00:20.317Z] github.com/pingcap/tiflow/dm/dm/pb.(*QueryStatusResponse).Marshal()
[2022-03-08T09:00:20.317Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/pb/dmworker.pb.go:3027 +0x54
[2022-03-08T09:00:20.317Z] google.golang.org/grpc/encoding/proto.codec.Marshal()
[2022-03-08T09:00:20.317Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/encoding/proto/proto.go:70 +0x23b
[2022-03-08T09:00:20.317Z] google.golang.org/grpc/encoding/proto.(*codec).Marshal()
[2022-03-08T09:00:20.317Z] <autogenerated>:1 +0x64
[2022-03-08T09:00:20.317Z] google.golang.org/grpc.encode()
[2022-03-08T09:00:20.317Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/rpc_util.go:545 +0x74
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).sendResponse()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:869 +0x184
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).processUnaryRPC()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1117 +0xb34
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).handleStream()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1405 +0x138b
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).serveStreams.func1.1()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746 +0xe6
[2022-03-08T09:00:20.318Z]
[2022-03-08T09:00:20.318Z] Goroutine 199 (running) created at:
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/worker.(*SourceWorker).EnableHandleSubtasks()
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/source_worker.go:434 +0xbcc
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/worker.(*Server).enableHandleSubtasks()
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/server.go:673 +0x195
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/worker.(*Server).operateSourceBound()
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/server.go:659 +0x2e8
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/worker.(*Server).handleSourceBound()
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/server.go:583 +0x511
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/worker.(*Server).observeSourceBound()
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/server.go:407 +0x108b
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/worker.(*Server).Start.func4()
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/worker/server.go:170 +0x114
[2022-03-08T09:00:20.318Z]
[2022-03-08T09:00:20.318Z] Goroutine 289 (running) created at:
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).serveStreams.func1()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:744 +0xb8
[2022-03-08T09:00:20.318Z] google.golang.org/grpc/internal/transport.(*http2Server).operateHeaders()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/internal/transport/http2_server.go:442 +0x1850
[2022-03-08T09:00:20.318Z] google.golang.org/grpc/internal/transport.(*http2Server).HandleStreams()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/internal/transport/http2_server.go:483 +0x49c
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).serveStreams()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:742 +0x1c7
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).handleRawConn.func1()
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:703 +0x4c
[2022-03-08T09:00:20.318Z] ==================
[2022-03-08T09:00:20.318Z] panic: runtime error: index out of range [-1]
[2022-03-08T09:00:20.318Z]
[2022-03-08T09:00:20.318Z] goroutine 1179 [running]:
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/pb.(*QueryStatusResponse).MarshalToSizedBuffer(0xc0059ddb40, 0xc00647c000, 0x272, 0x272, 0x150129f, 0xc000d1e000, 0xc000df5648)
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/pb/dmworker.pb.go:3082 +0x952
[2022-03-08T09:00:20.318Z] github.com/pingcap/tiflow/dm/dm/pb.(*QueryStatusResponse).Marshal(0xc0059ddb40, 0x61b5f40, 0xc0059ddb40, 0x7fb4e4351e08, 0xc0059ddb40, 0x1)
[2022-03-08T09:00:20.318Z] /home/jenkins/agent/workspace/dm_ghpr_integration_test/go/src/github.com/pingcap/tiflow/dm/dm/pb/dmworker.pb.go:3029 +0xa5
[2022-03-08T09:00:20.318Z] google.golang.org/grpc/encoding/proto.codec.Marshal(0x61b5f40, 0xc0059ddb40, 0x1, 0xc00006d040, 0xc0059ddb40, 0xc004fd33d0, 0xc0059ddb60)
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/encoding/proto/proto.go:70 +0x23c
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.encode(0x7fb4e45c3af8, 0xa295638, 0x61b5f40, 0xc0059ddb40, 0xa295638, 0x7, 0xf, 0x0, 0x6338d08)
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/rpc_util.go:545 +0x75
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).sendResponse(0xc000924000, 0x74bcbb8, 0xc000b88000, 0xc006478100, 0x61b5f40, 0xc0059ddb40, 0x0, 0x0, 0xc006bf034f, 0x0, ...)
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:869 +0x185
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).processUnaryRPC(0xc000924000, 0x74bcbb8, 0xc000b88000, 0xc006478100, 0xc000f68a50, 0x90b0840, 0x0, 0x0, 0x0)
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1117 +0xb35
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).handleStream(0xc000924000, 0x74bcbb8, 0xc000b88000, 0xc006478100, 0x0)
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1405 +0x138c
[2022-03-08T09:00:20.318Z] google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00022b240, 0xc000924000, 0x74bcbb8, 0xc000b88000, 0xc006478100)
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746 +0xe7
[2022-03-08T09:00:20.318Z] created by google.golang.org/grpc.(*Server).serveStreams.func1
[2022-03-08T09:00:20.318Z] /go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:744 +0xb9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified. The unit test changed to just checking if the returned result is a snapshot of the original one.
@@ -552,7 +552,10 @@ func (st *SubTask) markResultCanceled() bool { | |||
func (st *SubTask) Result() *pb.ProcessResult { | |||
st.RLock() | |||
defer st.RUnlock() | |||
return st.result | |||
tempProcessResult, _ := st.result.Marshal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd better check the error just for the sake of security.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I have modified the code and added the error handling.
return st.result | ||
tempProcessResult, _ := st.result.Marshal() | ||
newProcessResult := &pb.ProcessResult{} | ||
_ = newProcessResult.Unmarshal(tempProcessResult) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto. Or:
_ = newProcessResult.Unmarshal(tempProcessResult) | |
newProcessResult.Unmarshal(tempProcessResult) |
Is it necessary to decode and encode it again? What about deep copying the object?
*a = *b // a, b are pointers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it is necessary to decode and encode it, because Result() originally returns a pointer without the lock, which may cause data race when multiple functions are executing concurrently and calling Result(). In this case, deep copying would still return a pointer without the lock, which does not solve the problem. Here decoding and encoding again return a new copy of the process result, so that when multiple functions are calling Result() concurrently and using the returned pointer to modify things, they would be modifying the new copy, which has no effect on the original pointer, thus avoiding the potential data race.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified using deep copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ = newProcessResult.Unmarshal(tempProcessResult)
Here I cannot delete _ =, because 'make check' would fail and report error return value is not checked. Since it is guaranteed here that Unmarshal() will not return an error, so we can just ignore it.
dm/dm/worker/subtask_test.go
Outdated
st.result.IsCanceled = false | ||
go func() { | ||
for i := 0; i < 10; i++ { | ||
_, _ = tempQueryStatusResponse.Marshal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The for loop is just to increase the chances of running into data race, because one or two tests may not be able to fully check the issue. We'd better wait until these routines stop before exiting the test.
} | ||
cfg := &config.SubTaskConfig{ | ||
Name: "test-subtask-race", | ||
ValidatorCfg: config.ValidatorConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this issue do anything with the validator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. Sorry I am not quite familiar with the validator.
dm/dm/worker/subtask_test.go
Outdated
tempQueryStatusResponse.SubTaskStatus[0] = &tempSubTaskStatus | ||
for i := 0; i < 10; i++ { | ||
st.result.IsCanceled = false | ||
go func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wait until these routines stop before exiting this test or they are just detached?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The for loop is just to increase the chances of running into data race, because one or two tests may not be able to fully check the issue. We'd better wait until these routines stop before exiting the test.
dm/dm/worker/subtask.go
Outdated
tempProcessResult := st.result | ||
Errors := []*pb.ProcessError{} | ||
Detail := []byte{} | ||
immProcessResult := pb.ProcessResult{ | ||
IsCanceled: false, | ||
Errors: Errors, | ||
Detail: Detail, | ||
} | ||
var newProcessResult *pb.ProcessResult | ||
newProcessResult = &immProcessResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tempProcessResult := st.result | |
Errors := []*pb.ProcessError{} | |
Detail := []byte{} | |
immProcessResult := pb.ProcessResult{ | |
IsCanceled: false, | |
Errors: Errors, | |
Detail: Detail, | |
} | |
var newProcessResult *pb.ProcessResult | |
newProcessResult = &immProcessResult | |
var newProcessResult *pb.ProcessResult | |
newProcessResult = &pb.ProcessResult{} |
dm/dm/worker/subtask.go
Outdated
} | ||
var newProcessResult *pb.ProcessResult | ||
newProcessResult = &immProcessResult | ||
*newProcessResult = *tempProcessResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pb.ProcessResult.Errors
is an array of pointers, which should be deep copied as well.
*newProcessResult = *tempProcessResult | |
*newProcessResult = *st.Result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified back to Marshal() and Unmarshal(), which is less efficient than deep copy but easier to maintain (have been discussed).
dm/dm/worker/subtask_test.go
Outdated
var check bool | ||
if st.Result() == st.result { | ||
check = false | ||
} else { | ||
check = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var check bool | |
if st.Result() == st.result { | |
check = false | |
} else { | |
check = true | |
require.NotEqual(t, st.Result(), st.result) |
Only checking this is not sufficient (e.g. the pointers in the Errors
slice).
README.md
Outdated
@@ -1,9 +1,12 @@ | |||
# TiFlow | |||
|
|||
[![LICENSE](https://img.shields.io/github/license/pingcap/tiflow.svg)](https://github.com/pingcap/tiflow/blob/master/LICENSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see a lot of changes about readme and cdc, is that related to fixing this bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
She possibly rebase-merged the master🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I rebase-merged the master into my branch, probably shouldn't have done so. Only the changes in (*SubTask).Result() in dm/dm/worker/subtask.go and TestSubtaskRace() in dm/dm/worker/subtask_test.go are related to fixing this bug. I have fixed this problem, and now this PR should only contain the changes above.
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. @@ Coverage Diff @@
## master #5881 +/- ##
================================================
+ Coverage 57.0764% 57.4713% +0.3948%
================================================
Files 682 677 -5
Lines 80224 79765 -459
================================================
+ Hits 45789 45842 +53
+ Misses 30146 29679 -467
+ Partials 4289 4244 -45 |
dm/dm/worker/subtask_test.go
Outdated
|
||
func TestSubtaskRace(t *testing.T) { | ||
// to test data race of Marshal() and markResultCanceled() | ||
Errors := []*pb.ProcessError{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally local variables should not be public (capitalized)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified.
dm/dm/worker/subtask_test.go
Outdated
tempSubTaskStatus := pb.SubTaskStatus{} | ||
tempSubTaskStatus.Result = st.Result() | ||
tempQueryStatusResponse.SubTaskStatus[0] = &tempSubTaskStatus | ||
for i := 0; i < 10; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try that we can remove this loop and race detector still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried removing this loop and restoring the original Result(), and ran the unit test several times. It turned out that the race detector still worked. I have removed this loop.
/run-verify |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 2e56fa2
|
/run-dm-integration-test |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created: #5959. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created: #5960. |
In response to a cherrypick label: new pull request created: #5961. |
What problem does this PR solve?
Issue Number: close #4811
What is changed and how it works?
The Result() function now returns a new copy of the process result instead of directly returning the pointer without the lock, which may cause data race when multiple functions are executing concurrently, some calling Result() and writing into some variables that other functions are trying to read.
To solve the problem, first call Marshal() on the original process result, which will generate an intermediate process result. Then call Unmarshal() on the intermediate one and generate a new process result. Now the new process result is a copy of the original one, thus it can be the return parameter of Result().
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
No. The type of the return parameter is not changed, which is still *pb.ProcessResult, so this update will not affect those functions that call Result().
Do you need to update user documentation, design documentation or monitoring documentation?
No.
Release note