OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

[BUG] Use of Task.Result directly blocks thread #19176

Closed rfriend-zilo closed 1 month ago

rfriend-zilo commented 1 month ago

Bug Report Checklist

Description

The direct call here to Task.Result is blocking the thread, and when used in a blazor application prevents UI from rendering :

https://github.com/OpenAPITools/openapi-generator/blob/9ae877598713eff7c6b1bbb53c5b3b8ed22fa1f2/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache#L628

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/18915/files/0639c25fe8affd4c6ad8ea3d26711cc0f83a7bf1

Suggest a fix

Rather than calling async code from sync code using .Result, inside ExecAsync just await action() then construct Func<RestClient, RestResponse> getResponse using the result from that awaited call.

wing328 commented 1 month ago

Rather than calling async code from sync code using .Result, inside ExecAsync just await action() then construct Func<RestClient, RestResponse> getResponse using the result from that awaited call.

can you please file a PR with the suggested fix when you've time?

rfriend-zilo commented 1 month ago

My solution was not correct, my suggestion is to revert the changes in the PR.

wing328 commented 1 month ago

@filipe-silva can you please review this issue reported by @rfriend-zilo when you've time?

filipe-silva commented 1 month ago

@filipe-silva can you please review this issue reported by @rfriend-zilo when you've time?

This concern makes sense, I did a fix to resolve this issue. How do I merge it or include it in this PR?

wing328 commented 1 month ago

@filipe-silva can you please file a new PR?

wing328 commented 1 month ago

@rfriend-zilo can you please review the fix when you've time?

https://github.com/OpenAPITools/openapi-generator/pull/19231