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

Temporarily fix GridViewDataSet sync deadlocks. #481

Merged
merged 1 commit into from
Oct 27, 2017

Conversation

cafour
Copy link
Contributor

@cafour cafour commented Oct 18, 2017

Fixes deadlocks that occur when GridView synchronously calls asynchronous code that accesses a database from OnLoad/OnPreRender.

How about we add async version of OnInit, OnLoad, etc.?

@cafour cafour requested a review from exyi October 18, 2017 15:22
@djanosik
Copy link
Contributor

I don't understand this PR. Why is this necessary? Async code should not cause deadlocks unless you are waiting for the returned task later.

}
else if (OnLoadingDataAsync != null)
{
return await OnLoadingDataAsync(CreateGridViewDataSetLoadOptions());
return Task.FromResult(Task.Run(() => OnLoadingDataAsync(CreateGridViewDataSetLoadOptions())).Result);
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, but I have no idea why this s*** can fix something.

@cafour
Copy link
Contributor Author

cafour commented Oct 18, 2017

@djanosik But that's exactly what GridView does when it calls DataBind(). It refreshes its content thus calling OnLoadingDataAsync, which then causes a deadlock, because the task waits for the caller to return the context while the caller waits for the task to return the result.
When the OnLoadingDataAsync delegate gets called using Task.Run it gets executed in the thread pool context and thus doesn't cause the deadlock.

(Now that I think about it the Task.FromResult before the Task.Run is probably redundant. It gets waited later anyway though.)

@djanosik
Copy link
Contributor

djanosik commented Oct 18, 2017

I see. GridView calls GridViewDataSet.RequestRefresh() and it can indeed cause deadlocks. @exyi Is there any reason why lifetime events in controls are not async?

@exyi
Copy link
Member

exyi commented Oct 19, 2017

The control lifecycle methods are not async, because in one postback there is A LOT of invocations of them and having all of them async would cause significant performance overhead. The other reason is that I don't think that it's a good idea to put significant (-> async) logic into controls, you should just operate on data from view model. Unfortunately we have redesigned GridView to not follow this, so it causes the problems.

And when you really have to do that, it should not be a big deal to pause the worker thread and wait for the Task. Not a big deal from a performance point of view, but it's a problem when you have the stupid SynchronizationContext on the old ASP.NET platform.

@djanosik
Copy link
Contributor

That's a good point. Maybe the GridView should not request refresh in DataBind. Maybe it should just use data that are currently loaded in DataSet. It can request refresh when something is changed.

@djanosik
Copy link
Contributor

We will merge this PR to 1.1.0. But we need to find another solution.

@quigamdev quigamdev merged commit b2c7d15 into 1.1.0 Oct 27, 2017
@quigamdev quigamdev added this to the Version 1.1.7 milestone Oct 27, 2017
@quigamdev quigamdev deleted the dataset-sync-deadlocks branch February 5, 2018 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants