-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
The code generated by NSwag allows the consumer to pass a CancellationToken, which it uses on the call to HttpClient.SendAsync, but it doesn't use on the downstream call to response.Content.ReadAsStringAsync (or ReadAsStreamAsync).
This is a potential issue, because the NSwag-generated call to SendAsync uses HttpCompletionOption.ResponseHeadersRead, meaning the SendAsync call will return as soon as the headers are read (it will not wait for the full response body to be read, that will happen on the subsequent call to response.Content.ReadAsStringAsync).
The Microsoft Documentation suggests the use of the HttpCompletionOption.ResponseHeadersRead option means the following call to ReadAsStringAsync could block, because the CancellationToken (as well as the default timeout) only applies to the SendAsync call.
I am seeing this behavior at my end. Http log statements before and after the SendAsync call are appearing, but nothing afterward. My best guess is the host service becomes unresponsive during the ReadAsStringAsync call, causing an infinite block.