hertz icon indicating copy to clipboard operation
hertz copied to clipboard

feat: ReleaseRequest support async release

Open wzekin opened this issue 2 years ago • 2 comments

What type of PR is this?

feat

Check the PR title.

  • [x] This PR title match the format: <type>(optional scope): <description>
  • [x] The description of this PR title is user-oriented and clear enough for others to understand.

(Optional) Translate the PR title into Chinese.

为 ReleaseRequest 添加 async release 的支持

(Optional) More detail description for this PR(en: English/zh: Chinese).

en:

Question. In h1, client.Do is guaranteed to send the Request and then return. But in h2, client.Do will return directly after sending Request Header and receiving Response Header, so if we call ReleaseRequest directly after client.Do returns, Data Race will occur.

Solution. 1. add sendDone field and IsSendEnd, WaitSendEnd, SetSendEnd(internal) functions to Request to mark whether the request is sent or not 2. add a test at ReleaseRequest to check if the request is not sent, and async wait until it is finished

zh(optional):

问题: 在 h1 中,client.Do 保证发送完 Request 再返回。但在 h2 中,client.Do 会在发送完 Request Header 且接收到 Response Header 后直接返回,这时如果在 client.Do 返回后直接调用 ReleaseRequest 就会出现 Data Race。

解决方案: 1. 在Request 添加sendDone字段以及 IsSendEnd, WaitSendEnd, SetSendEnd(internal)函数,用于标记请求是否发送完成 2. 在 ReleaseRequest 中添加检测,如果未发送完成,则等待发送结束之后再释放 Request

Which issue(s) this PR fixes:

wzekin avatar Feb 13 '23 07:02 wzekin