Skip to content

fix: key not found exception when client never connects #1821

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

Conversation

NoelStephensUnity
Copy link
Collaborator

This fixes the issue where when a client would try to connect to a server but never established a connection it would throw a key not found exception.

NCCBUG-130

Changelog

com.unity.netcode.gameobjects

  • Fixed: Client throws a key not found exception when it times out using UNet or UTP.

Testing and Documentation

  • Includes integration tests.

This fixes the issue where if a client fails to connect after a specific period of time it will throw an exception because it never populated the m_TransportIdToClientIdMap.
this is a better way of handling this
The test for this fix where when a client cannot reach the server (i.e. times out) it would throw an exception complaining about a key not being found.  This test validates the fix for both UNet and UTP.
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review March 21, 2022 16:33
// for the disconnect event.
if (!IsServer && !m_TransportIdToClientIdMap.ContainsKey(clientId))
{
return clientId;
Copy link
Contributor

@jeffreyrainy jeffreyrainy Mar 21, 2022

Choose a reason for hiding this comment

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

return 0; ? That would be just as valid as we don't really have a clientId here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, that is the issue at hand... zero is typically the server and to return the "commonly" known server id (0) would also be confusing. Since it is ulong, we can't return a negative value... so I was just returning the transport since the client never made it to connecting.

Yeah... it is sort of a coin toss for me... as either way we will return an "invalid client id" and both identifiers will be "incorrect"...with the transport Id being the "most correct...incorrect" return value. (if that makes sense...lesser of two evils kind of thing)

changing the default return to be zero when a client fails to connect.
@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) March 21, 2022 17:24
@NoelStephensUnity NoelStephensUnity merged commit f1c61d3 into develop Mar 21, 2022
@NoelStephensUnity NoelStephensUnity deleted the fix/nccbug-131-key-exception-when-client-never-connects branch March 21, 2022 17:51
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.

2 participants