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

Clearing _netEventsQueue in NetManager.Start() not entirely threadsafe #131

Closed
GitFlip opened this issue Jan 12, 2018 · 1 comment
Closed
Assignees
Labels

Comments

@GitFlip
Copy link

GitFlip commented Jan 12, 2018

evt = _netEventsQueue.Dequeue();

Please correct me if I'm wrong, but if I stop my Client's connection to a server and switch to another server very quickly essentially calling Client.Stop() and then Client.Start() right after the OnPeerDisconnect Event is fired I will receive an error on line 919 that the _netEventsQueue is already equal to zero.

I haven't fully figured it out, but I'm guessing that I still have some events in the queue, thus I'm in that while loop. Then another thread of mine is calling Start() since I've processed the Disconnect event. Now the _netEventsQueue has been cleared while being processed since I called Start().

Currently my trigger for switching servers is having a thread wait for the client to receive the disconnected event and then connect to the next server, but it seems like I may in fact need to wait until all events have been processed, not just the disconnect. Either that, or their should be a lock around _netEventsQueue.Clear() in Start().

Any suggestions?

@GitFlip GitFlip changed the title Clearing _netEventsQueue in Start not entirely safe Clearing _netEventsQueue in NetManager.Start() not entirely threadsafe Jan 12, 2018
@RevenantX
Copy link
Owner

I will receive an error on line 919 that the _netEventsQueue is already equal to zero.

Yes. This is just bug) Thanks for report)

@RevenantX RevenantX added the bug label Jan 12, 2018
@RevenantX RevenantX self-assigned this Jan 12, 2018
RevenantX added a commit that referenced this issue Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants