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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decode issue for local activities returning nil result (#943) #1011

Merged

Conversation

vytautas-karpavicius
Copy link
Contributor

What changed?
Fix decode issue for local activities returning nil result (#943)

Why?
When local activity returns nil result, it is encoded into nil byte
slice ([]byte). Later this is converted into string field ResultJSON
within localActivityMarkerData structure. Such casting results in
empty string, as this is its zero value in golang.

Reverse conversion is not simetrical. Casting empty string back to
byte slice results in empty byte slice. This later causes EOF error
when trying to decode it back to the original result.

The fix is to check whether it is non-empty string and only then
assign the result back. This will be simetrical and will not cause
decoding error later.

How did you test it?
This change also adds additional replay tests, that covers this
scenario among many other local activity related cases.

Potential risks

When local activity returns nil result, it is encoded into nil byte
slice ([]byte). Later this is converted into string field ResultJSON
within localActivityMarkerData structure. Such casting results in
empty string, as this is its zero value in golang.

Reverse conversion is not simetrical. Casting empty string back to
byte slice results in empty byte slice. This later causes EOF error
when trying to decode it back to the original result.

The fix is to check whether it is non-empty string and only then
assign the result back. This will be simetrical and will not cause
decoding error later.

This change also adds additional replay tests, that covers this
scenario among many other local activity related cases.
@coveralls
Copy link

coveralls commented Jul 22, 2020

Pull Request Test Coverage Report for Build fc7169fc-8cd2-433e-9127-2d2019690935

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 74.675%

Totals Coverage Status
Change from base Build 194eea71-73fe-406a-a5fd-4d250fc1366e: 0.04%
Covered Lines: 9359
Relevant Lines: 12533

💛 - Coveralls

@vancexu
Copy link
Contributor

vancexu commented Jul 22, 2020

Another related task when you have time, could you also check if there are similar edge cases in other marker events (SideEffect/MutableSideEffect/GetVersion)? if not, maybe worth to add unit tests as what you provide in this PR. Thanks

@meiliang86 meiliang86 merged commit 73287b6 into uber-go:master Jul 22, 2020
@meiliang86
Copy link
Contributor

Fixes #943

@vytautas-karpavicius vytautas-karpavicius deleted the fix-local-activity-nil-return branch July 22, 2020 17:28
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

Successfully merging this pull request may close these issues.

None yet

4 participants