buttplugio / buttplug-rs-ffi

FFI from buttplug-rs to Java and other languages
Other
89 stars 22 forks source link

C# dispose methods should handle re-entrancy #79

Closed qdot closed 3 years ago

qdot commented 3 years ago

Describe the bug

Code block from ScriptPlayer

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            ButtplugClient client1 = new ButtplugClient("Testclient");
            client1.ServerDisconnect += Client1OnServerDisconnect;
            await client1.ConnectAsync(new ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345/buttplug")));
            await client1.DisconnectAsync();
            client1.Dispose();
        }

        private void Client1OnServerDisconnect(object sender, EventArgs eventArgs)
        {
            ((ButtplugClient)sender).Dispose();
        }

Expected behavior

No crash

Actual behavior

Random crashes, though completely repro'able in debug because the tasks will be slowed down enough to cause re-entrance on the Dispose call, meaning we'll pass the logic check and try to delete twice.

Additional context

Lock object will fix it.