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

[Adhoc] Fix possible lock issue and Updated PdpStat #14060

Merged
merged 2 commits into from
Feb 4, 2021

Conversation

anr2me
Copy link
Collaborator

@anr2me anr2me commented Feb 4, 2021

  • Fix possible lock issue during AdhocMatchingStart
  • Updated PdpStat to prevent rcv_sb_cc from exceeding the buffer size arg (since we use larger buffer size to prevent micro stutters or disconnection issue due to too many dropped packets with small buffer size).
    TODO: May need to improve it to be able to calculate the correct size if there are multiple datagram messages

…rg (since we use larger buffer size to prevent micro stutters or disconnection issue due to too many dropped packets with small buffer size).

TODO: May need to improve it to be able to calculate the correct size if there are multiple datagram messages
static int lastUdpBufSize = 0;
static char* buf = NULL;
if (udpBufferSize > lastUdpBufSize) {
// Reusing temp buffer to prevent causing too many fragmentation due to repeated alloc -> free (was getting out of memory issue)
Copy link
Owner

Choose a reason for hiding this comment

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

if you were really running out of memory, you would have been leaking. I don't think fragmentation here would cause such serious issues..

Copy link
Collaborator Author

@anr2me anr2me Feb 4, 2021

Choose a reason for hiding this comment

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

It might not be fragmentation, i only gets out of memory (my monitor goes blank and a popup related to memory appeared) when debugging it through Visual Studio 2019, may be it's VS Debugger bug on memory allocation?
It's just a simple:

char *buf = (char*)malloc(size);
err = recvfrom(...);
free(buf);

So i can't really tell where the leaks came from, and i certainly don't want to get issue while debugging.

Copy link
Owner

Choose a reason for hiding this comment

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

That's really odd, something like that shouldn't run of RAM.

However, if realloc fixes it, let's go with that, I guess..

Copy link
Collaborator Author

@anr2me anr2me Feb 4, 2021

Choose a reason for hiding this comment

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

Hmm... i think we don't really need to provide a large buffer since we only need to retrieved the message size, and it seems with MSG_TRUNC we can provide small buffer and it will still return the actual message size (one full message)

@hrydgard
Copy link
Owner

hrydgard commented Feb 4, 2021

What games have issues that this will fix? Just curious.

@anr2me
Copy link
Collaborator Author

anr2me commented Feb 4, 2021

Currently there are no game that have issue with current socket stats, just trying to get the stat data correctly. While the lock/unlock issue is certainly something that need to be fixed (although normally almost never reach that point of code)

There is one game i know that relies on the number of byte available to receive and affects the FPS, which is Warriors Orochi 2.
This game will wait until there are not enough data to be received before rendering new frame, otherwise it will keeps receiving in a loop to drains the buffer, so if the buffer is too large and filled up it could cause the FPS & VPS to drops to 0/0.

My previous solution to prevent the FPS/VPS from dropping too much was by reducing the buffer size, but apparently VPN doesn't worked well with small buffer size (may be due to higher latency it need to be able to buffer more data).
Capping the number of bytes up to the buffer size arg set by the game is just an extra prevention of FPS drops on games that relies on the rcv_sb_cc value like Warriors Orochi 2.

@hrydgard hrydgard merged commit d3d5ff0 into hrydgard:master Feb 4, 2021
@hrydgard hrydgard added this to the v1.11.0 milestone Feb 4, 2021
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