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 race condition when handling plugins packets #1673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Spasitjel
Copy link

There's a race condition in the access of the packets CircularBuffers, between the render thread, which reads the packets from the Server->Client buffer, the Plugin->Client buffer and the Plugins thread which can enqueue new packets to be read by the Client.

Add a lock when appending data to each of the receiving buffers. Remove the lock to the packet handler when the plugin appends new packets.

Fixes #1665
Fixes #1618

This is the second attempt, more info also at #1670

There's a race condition in the access of the packets CircularBuffers,
between the render thread, which reads the packets from the Server->Client buffer,
the Plugin->Client buffer and the Plugins thread which can enqueue new
packets to be read by the Client.

Add a lock when appending data to each of the receiving buffers.
Remove the lock to the packet handler when the plugin appends
new packets.
Copy link

@Coji4000 Coji4000 left a comment

Choose a reason for hiding this comment

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

This looks like it should add stability to packet reads. Helping to alleviate incorrect offsetting of packet data.

@Coji4000
Copy link

This looks like it should add stability to packet reads. Helping to alleviate incorrect offsetting of packet data.

I built with this last night and still experienced the issue after a couple hours. I got the endless page flipping book and frozen character. I've been using this script to recreate. still takes a few hours sometimes.

Walk("West")
Walk("West")
Walk("East")
Walk("East")
UseSkill("Arms Lor")
WaitForTarget(2000)
Target("last")
Pause(2000)
UseSkill("Hidin")
Pause(3000)    

@Spasitjel
Copy link
Author

Spasitjel commented May 18, 2024

This looks like it should add stability to packet reads. Helping to alleviate incorrect offsetting of packet data.

I built with this last night and still experienced the issue after a couple hours. I got the endless page flipping book and frozen character. I've been using this script to recreate. still takes a few hours sometimes.

Walk("West")
Walk("West")
Walk("East")
Walk("East")
UseSkill("Arms Lor")
WaitForTarget(2000)
Target("last")
Pause(2000)
UseSkill("Hidin")
Pause(3000)    

I think the issue you are experiencing here might be related to: #1674

There may be some other bug actually unrelated to this that it's now surfaced due to the fix.

But without this fix I was almost unable to use scripts, due to crashes, and so on.
Pauses in the script would alleviate it a little, but those were just palliatives, and they should not be needed.

@Coji4000
Copy link

This looks like it should add stability to packet reads. Helping to alleviate incorrect offsetting of packet data.

I built with this last night and still experienced the issue after a couple hours. I got the endless page flipping book and frozen character. I've been using this script to recreate. still takes a few hours sometimes.

Walk("West")
Walk("West")
Walk("East")
Walk("East")
UseSkill("Arms Lor")
WaitForTarget(2000)
Target("last")
Pause(2000)
UseSkill("Hidin")
Pause(3000)    

I think the issue you are experiencing here might be related to: #1674

There may be some other bug actually unrelated to this that it's now surfaced due to the fix.

But without this fix I was almost unable to use scripts, due to crashes, and so on. Pauses in the script would alleviate it a little, but those were just palliatives, and they should not be needed.

You may be right but I think the condition occurs when compressed packets are sent from the server and irritates the race condition. I'll reply to #1674 with some packet logs snips showing why I feel that way. I was getting the issue both before and after using your pull req. the playerupdate packet ID: 78 is one of the compressed packets as well as ID: AE. both are in my packetdumps from CUO but don't show up in a wireshark trace because they are compressed which shifts the byte data. I think it is the decompression of these packets that is creating the issue you and I are experiencing. It only occurs when a plugin is active in my experience though admittedly it's very difficult to test without macros. I'll stop derailing this thread and add to 1674

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.

Race condition in handling plugins packets System.ArgumentException: Destination is too short
2 participants