I am not getting a response from the async DocumentDB ReplaceDocument method when running in a web context (IIS). When running locally, it works just fine. From my research this is appears something to do with a conflicting deadlock with a UI thread?
I am getting good responses from other async calls like so:
this.Client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(this.DatabaseName)).Result;
// and
this.Client.CreateDatabaseAsync(new Database { Id = this.DatabaseName }).Result;
// etc
I'm not using await as in an IIS context is seems to never respond. I'm not sure why, so I removed all the async awaits, and started using .Result
and everything works now except the below method.
According to this question Call to await GetFileAsync() never returns and app hangs in WinRT app . I have set up the ConfigureAwait(false)
and am calling GetResult()
. But the method doesn't return, and the thread eventually closes without return.
var task = this.Client.ReplaceDocumentAsync(this.GetDocumentLink(d.id), d, options);
var configuredTask = task.ConfigureAwait(false);
var awaiter = configuredTask.GetAwaiter();
var result = awaiter.GetResult();
I have also tried the following permutations:
// in a spereate async method
await this.Client.ReplaceDocumentAsync(this.GetDocumentLink(d.id), d, options);
await this.Client.ReplaceDocumentAsync(this.GetDocumentLink(d.id), d, options).ConfigureAwait(false);
// as well as trying a call back
.GetAwaiter().OnCompleted(() => /* never gets here either */);
EDIT
I have this in my Web.config
(via :What's the meaning of "UseTaskFriendlySynchronizationContext"?)
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
and
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.5" />
</system.web>