-
Notifications
You must be signed in to change notification settings - Fork 41
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
Possible logic error in Stop() #189
Comments
IMHO this could be a problem of testing.T.Log, not of the client
// ClientClosed
//
// The Client is not able to send and receive messages anymore and has to be started again to be able to. Did you observe that this was not the case after calling Stop? |
Yes it is a problem of
Yes by having goroutines still logging
Yes because the client just sets the state to Therefore I created #188 to fix the problem. In the original version the test works but with the fix attempt the test fails there (So test itself is good to be used upstream). |
It looks like #188 does just delay the return of the function. It ends when the WaitForState returns. But the WaitForState mechanism involves goroutines and channels, so the necessary context switches can take place and the goroutines are ending. I don't see any benefit in making It would be possible to add special sync.WaitGroup to all started goroutines to make it safely synchronous, but as I said, I don't see the benefit over a simple |
yes and it would be good if we have a sync.WaitGroup like you describe below.
I thought so, hence the PR is still a WIP as we need indeed a sync.WaitGroup to check if all spawned goroutines are gone.
One benefit would be that there are no go routines running anymore after you call
I listed some benefits above (no leaking goroutines, |
There are no leaking goroutines. The all come to an end when the go runtime scheduler checks them the next time, as they all on a select statement when no signalr protocol work has to be done. But the order the scheduler does this and so the time they when all are ended can not be determined exactly. What remains is the panic or race in testing. If you look at the code in testing.go, you will see that both results are in there to help detect not appropriately synchronized goroutines. But for signalr this is a false positive. If you like, you can try to implement the |
I will add the |
I updated #188 and added WaitGroup additions rarely where it made direct sense. On other go routines that were spawned as a direct result of a client action (Client should not really call those after |
Looking at the
Stop
method inclient.go:220
I was wondering if the logic is wrong.At the moment the state is being set immediately:
which should rather be
Rational: When calling stop you really want the client to stop. Stopped means that no more go routine is running
Effect: At the moment when you redirect the logger to
t.Testing
Log
you get Dataraces when run with-race
I created a PR for that to show the issue with a proper test case #188. (Even with the updated code I run into a timeout)
The text was updated successfully, but these errors were encountered: