Skip to content
This repository has been archived by the owner. It is now read-only.

Deadlock reachable from RetrieveData #9

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

Deadlock reachable from RetrieveData #9

anirudhsanthiar opened this issue Jan 4, 2016 · 3 comments

Comments

@anirudhsanthiar
Copy link
Contributor

@anirudhsanthiar 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
Copy link

@alexeyqian alexeyqian commented Mar 8, 2016

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

@panjkov
Copy link
Contributor

@panjkov 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
…entAsync to not capture context (to prevent a deadlock reachable from GetResponseXML)
@anirudhsanthiar
Copy link
Contributor Author

@anirudhsanthiar 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants