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

Deadlock in WebRequesterBasic #46

Closed
anirudhsanthiar opened this issue Jan 4, 2016 · 4 comments
Closed

Deadlock in WebRequesterBasic #46

anirudhsanthiar opened this issue Jan 4, 2016 · 4 comments

Comments

@anirudhsanthiar
Copy link

@anirudhsanthiar anirudhsanthiar commented Jan 4, 2016

In the WebRequesterBasic class, we have the following method:

public HttpWebResponse IssueWebRequest(string endpoint, string method = "GET", Stream input =   null)
{
   var response =  IssueWebRequestAsync(endpoint, method, input).Result;
   return response;
}

A GUI client (such as a Windows Forms app) or an MVC client will deadlock if it calls the method as follows:
var requester = new Microsoft.HBase.Client.WebRequesterBasic(); requester.IssueWebRequest("https://github.com/hdinsight/hbase-sdk-for-net");

Mixing synchronous and asynchronous waiting is dangerous, see, for example http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

There are instances of synchronous blocking in WebRequesterSecure and WebRequester as well.
A possible fix would be to configure the awaits IssueWebRequestAsync to not capture the current SynchronizationContext using ConfigureAwait(false)

@duoxu
Copy link
Contributor

@duoxu duoxu commented Jan 7, 2016

Do the following options work for you?

1.override the SynchronizationContext

var sc = new SynchronizationContext();
SynchronizationContext.SetSynchronizationContext(sc);
{
Invoke SDK commands here
}
2. Start an Async task
Task.Run(async () =>
{
Invoke SDK commands here
});

@anirudhsanthiar
Copy link
Author

@anirudhsanthiar anirudhsanthiar commented Jan 7, 2016

The latter would work. I'm curious as to why you haven't configured the await's in IssueWebRequestAsync - are there objects with thread affinity that are accessed by this method?

@anirudhsanthiar
Copy link
Author

@anirudhsanthiar anirudhsanthiar commented Feb 10, 2016

Could you either add a warning to the documentation asking users to not call methods like IssueWebRequest from a GUI context, or perhaps configure the await statements in the library to not capture context via ConfigureAwait(false) [see, for example, the section under "avoiding context" in 1]

@duoxu
Copy link
Contributor

@duoxu duoxu commented Mar 24, 2016

@anirudhsanthiar We are planning to expose async APIs only, so that it will not confuse people any more.

@duoxu duoxu closed this Mar 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.