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 Subscribe panic and add a test which would have caught it #74

Merged
merged 3 commits into from
Jan 7, 2022

Conversation

nshalman
Copy link
Member

@nshalman nshalman commented Jan 6, 2022

Description

This PR creates a new test for the Subscribe endpoint as well as fixing a current bug which causes panics when that RPC is used.

Why is this needed

Fixes: #69

How Has This Been Tested?

~/Workspace/hegel % go test -run TestSubscribe -count 2000 ./grpc-server/...
ok  	github.com/tinkerbell/hegel/grpc-server	15.102s

~/Workspace/hegel % git revert --no-edit 88728c4
Auto-merging grpc-server/grpc_server.go
[nshalman/subscribe-fix-and-test 1d53e08] Revert "subLock needs to be initialized"
 Date: Fri Jan 7 13:14:24 2022 -0500
 1 file changed, 1 deletion(-)

~/Workspace/hegel % go test -run TestSubscribe ./grpc-server/...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x107525e]

goroutine 104 [running]:
sync.(*RWMutex).Lock(0xc00031d080)
<snip>

How are existing users impacted? What migration steps/scripts do we need?

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@nshalman nshalman requested a review from mmlb January 6, 2022 20:16
@nshalman nshalman self-assigned this Jan 6, 2022
@nshalman nshalman force-pushed the nshalman/subscribe-fix-and-test branch 4 times, most recently from 2ae2cf5 to 6699895 Compare January 6, 2022 20:39
@codecov
Copy link

codecov bot commented Jan 6, 2022

Codecov Report

Merging #74 (4b367ad) into main (bb62536) will increase coverage by 16.10%.
The diff coverage is 58.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #74       +/-   ##
===========================================
+ Coverage   33.89%   50.00%   +16.10%     
===========================================
  Files           3        3               
  Lines         413      422        +9     
===========================================
+ Hits          140      211       +71     
+ Misses        250      177       -73     
- Partials       23       34       +11     
Impacted Files Coverage Δ
grpc-server/grpc_server.go 54.33% <58.33%> (+40.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb62536...4b367ad. Read the comment docs.

@nshalman nshalman force-pushed the nshalman/subscribe-fix-and-test branch from 6699895 to f0ae94c Compare January 7, 2022 16:39
@nshalman
Copy link
Member Author

nshalman commented Jan 7, 2022

Thanks again to @mmlb for most of this test harness, and for the pointers for the further cleanup of the tests in https://github.com/tinkerbell/hegel/compare/669989512f74834d3a41cbcc271cf03cb152c630..f0ae94cd34199f0d1d1ce3c90e64dfb8ad9111a5

@mmlb
Copy link
Contributor

mmlb commented Jan 7, 2022

Thanks again to @mmlb for most of this test harness, and for the pointers for the further cleanup of the tests in 669989512f74834d3a41cbcc271cf03cb152c630..f0ae94cd34199f0d1d1ce3c90e64dfb8ad9111a5 (compare)

np. now that I look again the WaitGroup is probably unnecessary and I forgot to drop it

@nshalman
Copy link
Member Author

nshalman commented Jan 7, 2022

now that I look again the WaitGroup is probably unnecessary and I forgot to drop it

Good catch. I will clean that up.

Edit: Cleaned up in https://github.com/tinkerbell/hegel/compare/f0ae94cd34199f0d1d1ce3c90e64dfb8ad9111a5..b149044946bc8f3de8db4607f3851b37e9e3d75a

@nshalman nshalman force-pushed the nshalman/subscribe-fix-and-test branch from f0ae94c to b149044 Compare January 7, 2022 17:26
tobert
tobert previously approved these changes Jan 7, 2022
Copy link
Contributor

@tobert tobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read it over and think I understand what's happening and it looks fine to me. Thanks for adding this!

Copy link
Contributor

@mmlb mmlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few minor nits the only one I'd really like to see fixed is the comment on startServersAndConnectClient

Comment on lines 64 to 68
var m sync.RWMutex
s := &Server{
log: l,
hardwareClient: hc,
subLock: &m,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var m sync.RWMutex
s := &Server{
log: l,
hardwareClient: hc,
subLock: &m,
s := &Server{
log: l,
hardwareClient: hc,
subLock: &sync.RWMutex{},

should work too and doesn't need a unnecessary variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

zt.mu.RUnlock()
}

// serveAndDial starts 2 grpc services.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be startServersAndConnectClient

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the rest of the comment updated too. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

})

t.Run("good", func(t *testing.T) {
// id := uuid.Must(uuid.NewRandom()).String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be deleted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 48 to 51
data := map[string]string{}
value := fmt.Sprintf(`{"id": "%s", "ip": "%s"}`, id, id)
payload := fmt.Sprintf(`%s=%s`, id, value)
data[id] = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be:

Suggested change
data := map[string]string{}
value := fmt.Sprintf(`{"id": "%s", "ip": "%s"}`, id, id)
payload := fmt.Sprintf(`%s=%s`, id, value)
data[id] = value
value := fmt.Sprintf(`{"id": "%s", "ip": "%s"}`, id, id)
payload := fmt.Sprintf(`%s=%s`, id, value)
data := map[string]string{
id: value,
}

but not a big deal to change really

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

nshalman and others added 2 commits January 7, 2022 13:11
Fixes #69

Signed-off-by: Nahum Shalman <[email protected]>
This allows us to accept "bufconn" connections during testing
without causing panics

Signed-off-by: Nahum Shalman <[email protected]>
Co-authored-by: Manuel Mendez <[email protected]>
@nshalman nshalman force-pushed the nshalman/subscribe-fix-and-test branch from b149044 to 0bd1af9 Compare January 7, 2022 18:11
Signed-off-by: Nahum Shalman <[email protected]>
Co-authored-by: Manuel Mendez <[email protected]>
@nshalman nshalman force-pushed the nshalman/subscribe-fix-and-test branch from 0bd1af9 to 4b367ad Compare January 7, 2022 18:22
@nshalman nshalman requested a review from mmlb January 7, 2022 18:23
Copy link
Contributor

@mmlb mmlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@nshalman nshalman added the ready-to-merge Signal to Mergify to merge the PR. label Jan 7, 2022
@mergify mergify bot merged commit df55fcc into main Jan 7, 2022
@mergify mergify bot deleted the nshalman/subscribe-fix-and-test branch January 7, 2022 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Signal to Mergify to merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

otelgrpc.StreamServerInterceptor -> panic: runtime error: invalid memory address or nil pointer dereference
3 participants