-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ReleaseRequest support async release #608
Conversation
Codecov ReportBase: 72.07% // Head: 71.91% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #608 +/- ##
===========================================
- Coverage 72.07% 71.91% -0.16%
===========================================
Files 96 96
Lines 9389 9411 +22
===========================================
+ Hits 6767 6768 +1
- Misses 2189 2210 +21
Partials 433 433
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
pkg/protocol/http1/client.go
Outdated
@@ -523,11 +523,18 @@ func (c *HostClient) doNonNilReqResp(req *protocol.Request, resp *protocol.Respo | |||
} | |||
zw := c.acquireWriter(conn) | |||
|
|||
// need this? in fact, IsSendEnd always return true in h1 | |||
sendDone := make(chan struct{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is no need in h1
0ac76f6
to
11f2069
Compare
11f2069
to
77bbe08
Compare
77bbe08
to
3a58309
Compare
@@ -814,6 +818,36 @@ func (req *Request) SetConnectionClose() { | |||
req.Header.SetConnectionClose(true) | |||
} | |||
|
|||
// IsSendEnd return true if the client has sent all data of this request | |||
func (req *Request) IsSendEnd() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change it to private method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is used by http2
} | ||
|
||
// WaitSendEnd will wait until the client has sent all data of this request | ||
func (req *Request) WaitSendEnd() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AA
// SetSendDone set a sendDone channel to Request | ||
// | ||
// NOTE: It is an internal function. You should not use it. | ||
func (req *Request) SetSendDone(sendDone <-chan struct{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AA
possible to expedite this merge? |
What type of PR is this?
feat
Check the PR title.
(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 callReleaseRequest
directly afterclient.Do
returns, Data Race will occur.Solution.
1. add
sendDone
field andIsSendEnd
,WaitSendEnd
,SetSendEnd(internal)
functions toRequest
to mark whether the request is sent or not2. add a test at
ReleaseRequest
to check if the request is not sent, and async wait until it is finishedzh(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
中添加检测,如果未发送完成,则等待发送结束之后再释放 RequestWhich issue(s) this PR fixes: