Recently, the integration of Elasticclient client in the system, automatically create indexes, delete indexes, found that through elasticclient lowerlevelclient can not return the results correctly, but the index has been successfully created or deleted.
and will throw the exception "A task was cancelled" in the time-out period, check the official documents and Google are no solution.
Try again in the morning, use httpclient direct access, still the same problem.
Helpless, sacrifice fiddler, carry out request analysis.
1) Use composer to simulate the request, the simplest get operation, actually can not return the result immediately
2) direct access using the browser to return the results correctly
3) Compare the HTTP request header, the Fiddler request header is basically empty, from the browser to copy the Fiddler request header come over, finally found, plus the following request header, will be able to correctly return the results:
Accept-encoding:gzip, deflate
4) corresponding to the httpclient, you can use the following method to solve the
New Httpclienthandler () { = Decompressionmethods.gzip | decompressionmethods.deflate }; var New HttpClient (handler) { new Uri ($"http://{es_host}:{es_port}") };
Use this httpclient to access the Elasticsearch and immediately return to the results.
problem Analysis: the server side will return the result by default using gzip compression, but the client does not handle data decompression by default, causing the client to read the data, can not tell whether the data has been read, has been suspended until the timeout, and then throw "A task was Canceled "error.
HttpClient Other "A task was Canceled" errors, most likely due to incorrect HTTP header settings, and the server has requirements for client features, such as gzip for this example.
"A task was cancelled" error when you resolve a. NET HttpClient call