-
Notifications
You must be signed in to change notification settings - Fork 538
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
Possible race condition in proxy object creation #9862
Comments
If it's expected that a second proxy object can be instantiated (*), then feel free to delegate the issue to dotnet/maui because they depend on the behaviour that this doesn't happen by saving the instance to a static variable: This in turn is accessed all over that place. With the example stack traces above, once the (*) I very much doubt it's intentional; if there were data associated with the object it would create a lot of issues. |
Do you have a small example of your Typical operation would be:
But I wonder if no. 3 can start happening in parallel with 2. |
The source code for the worker itself is likely not interesting - https://gist.github.com/filipnavara/c8e196bb1bd4471a00174708366ef6ff. What is likely more interesting is how the worker is scheduled: var syncWorkRequest = (PeriodicWorkRequest.Builder.From<SyncWorker>(TimeSpan.FromMinutes(15))
.SetConstraints(new Constraints.Builder().SetRequiredNetworkType(NetworkType.Connected).Build())
.SetInitialDelay(15, TimeUnit.Minutes) as PeriodicWorkRequest.Builder).Build();
WorkManager.GetInstance(context).EnqueueUniquePeriodicWork("sync", ExistingPeriodicWorkPolicy.Update, syncWorkRequest); The traces we get from customers suggest that it's often happening after clicking on a notification. It's likely that the "required network type" constraint may play a role because some devices tend to do a "soft sleep" mode for network connections when locked. In this scenario it's more likely that the worker will get triggered alongside creation of the activity to handle the notification. That said, it's just a theory. We don't have repro on any of our own devices and we have tried for weeks. Weirdly it happens to a large percent of customers in the wild regularly enough. I don't see any locking in |
Android framework version
net8.0-android
Affected platform version
VS 2022 17.12.4
Description
We spent the last few weeks trying to track down a mysterious bug where two instances of
Android.App.Application
.NET proxy objects are created. So far we were not able to reproduce the issue locally but it happens quite consistently for thousands of our customers.Finally we were able to get stack traces from the constructor where the second instance is created.
The usual first instance gets created with this stack trace:
The second instance comes from a worker (subclass of
AndroidX.Work.Worker
):Notably, the first instance exists and it's not collected on the .NET side (pinned through a static variable). This suggests that there's a race condition that could lead to creation of two proxy objects.
Steps to Reproduce
Unfortunately, we don't have a repro. I'll update the issue if we manage to make a synthetic repro.
Did you find any workaround?
No response
Relevant log output
The text was updated successfully, but these errors were encountered: