ngocnicholas / airtable.net

Airtable .NET API Client
MIT License
140 stars 34 forks source link

Thread deadlock before Airtable data is returned #28

Closed mcamporelli closed 4 years ago

mcamporelli commented 4 years ago

First of all, thanks for your work on this great library.

We implemented the sample code to retrieve some records (which you provided in the documentation) in our ASP.NET project. However, we only seem to get the async methods working when we add a Thread.Sleep between the actual call and the task await statement. If we omit it, it seems like a deadlock occurs and the subsequent code is never executed.

So, for example, this works: Task<AirtableListRecordsResponse> task = airtableBase.ListRecords(tableName, offset, fieldsToRetrieve, filterByFormula, maxRecords, pageSize, sort, view); Thread.Sleep(2000); var response = await task;

...and this does not: Task<AirtableListRecordsResponse> task = airtableBase.ListRecords(tableName, offset, fieldsToRetrieve, filterByFormula, maxRecords, pageSize, sort, view); var response = await task;

Do you know what might be causing this behavior? Any help is greatly appreciated.

ngocnicholas commented 4 years ago

The await operator suspends evaluation of the enclosing async method until the asynchronous operation represented by its operand (airtableBase.ListRecords) completes.

Thread.Sleep(2000) suspends the current thread for 2000 milliseconds. Even though the Thread.Sleep call is completely redundant, airtableBase.ListRecords should get its turn to run in both situations. The deadlock observed must be caused by other code in your environment. Try to strip your test down to a minimum and see what happen. If the problem persists, please provide a minimum repro.