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 reachable from RetrieveData #9

Open
anirudhsanthiar opened this Issue Jan 4, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@anirudhsanthiar
Contributor

anirudhsanthiar commented Jan 4, 2016

The code below deadlocks o365rwsclient when invoked from a GUI app (such as a Windows Forms app) or an MVC appllication.

            ReportingContext context = new ReportingContext();
            context.UserName = @"YOUR O365 EMAIL ADDRESS";
            context.Password = @"YOUR O365 PASSWORD";
            context.FromDateTime = DateTime.MinValue;
            context.ToDateTime = DateTime.MinValue;
            context.SetLogger(new DefaultLogger());

            IReportVisitor visitor = new DefaultReportVisitor();

            ReportingStream stream = new ReportingStream(context, "MailboxActivityDaily", "stream1");
            stream.RetrieveData();

The reason is that RetrieveData eventually calls GetResponseXml. The method
public List<XmlNode> GetResponseXml(Type reportType, QueryFilter filter) has the line
Stream responseContent = GetResponseContentAsync(serviceFullUrl).Result;

Blocking on the results of asynchronous methods is dangerous: see, for example,
http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

A possible fix is to configure the awaits in GetResponseContentAsync to not capture context using ConfigureAwait(false).

@alexeyqian

This comment has been minimized.

alexeyqian commented Mar 8, 2016

Spent hours on this issue which makes this client library useless in Web application. Hope fix it soon.

@panjkov

This comment has been minimized.

Contributor

panjkov commented May 11, 2016

Hi, apologies for late reply.
@alexeyqian @anirudhsanthiar did you already try to fork the codebase and play around with changes mentioned in the Stephen Cleary's blog?
If not, I will try it in next few weeks.

anirudhsanthiar added a commit to anirudhsanthiar/o365rwsclient that referenced this issue May 24, 2016

Fix for issue Microsoft#9. Configured the awaiters in GetResponseCont…
…entAsync to not capture context (to prevent a deadlock reachable from GetResponseXML)
@anirudhsanthiar

This comment has been minimized.

Contributor

anirudhsanthiar commented May 24, 2016

@panjkov Please see this pull request. Another option is to make o365rwsclient fully asynchronous by making GetResponseXML and all its callers asynchronous. This will mean a bigger refactoring - would the developers be willing to accept a pull request that does it?

julienjtpierre added a commit that referenced this issue May 25, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment