Repository: cloudwego/hertz
Pull request #687 (2023-03-24 10:50:32)

optimize: DialTimeout provided by netpoll will return TLS err directly
#### What type of PR is this?
<!--
Add one of the following kinds:

build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
docs: Documentation only changes
feat: A new feature
optimize: A new optimization
fix: A bug fix
perf: A code change that improves performance
refactor: A code change that neither fixes a bug nor adds a feature
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc)
test: Adding missing tests or correcting existing tests
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
-->
optimize

#### Check the PR title.
<!--
The description of the title will be attached in Release Notes, 
so please describe it from user-oriented, what this PR does / why we need it.
Please check your PR title with the below requirements:
-->
- [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.


#### (Optional) More detail description for this PR(en: English/zh: Chinese).
<!--
Provide more detailed info for review. If it is a perf type PR, perf data is suggested to give.
-->
en: netpoll return the "not support tls" error instead. refer to https://github.com/cloudwego/hertz/pull/672#issuecomment-1475864569
zh(optional): netpoll 返回不支持 tls 的错误信息。 参考 https://github.com/cloudwego/hertz/pull/672#issuecomment-1475864569



#### Which issue(s) this PR fixes:
<!--
Automatically closes linked issue when PR is merged.
Eg: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->


codecov[bot]: ## [Codecov](https://codecov.io/gh/cloudwego/hertz/pull/687?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) Report
Patch coverage: **`100.00`**% and project coverage change: **`+0.05`** :tada:
> Comparison is base [(`140053c`)](https://codecov.io/gh/cloudwego/hertz/commit/140053cb2db42fdcd992198a3da1db384dd17bc5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) 75.55% compared to head [(`d9b43fd`)](https://codecov.io/gh/cloudwego/hertz/pull/687?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) 75.61%.

> :exclamation: Current head d9b43fd differs from pull request most recent head 0947b18. Consider uploading reports for the commit 0947b18 to get more accurate results

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           develop     #687      +/-   ##
===========================================
+ Coverage    75.55%   75.61%   +0.05%     
===========================================
  Files           96       96              
  Lines         9433     9435       +2     
===========================================
+ Hits          7127     7134       +7     
+ Misses        1860     1854       -6     
- Partials       446      447       +1     
```


| [Impacted Files](https://codecov.io/gh/cloudwego/hertz/pull/687?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) | Coverage Δ | |
|---|---|---|
| [pkg/network/netpoll/dial.go](https://codecov.io/gh/cloudwego/hertz/pull/687?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego#diff-cGtnL25ldHdvcmsvbmV0cG9sbC9kaWFsLmdv) | `100.00% <100.00%> (ø)` | |

... and [1 file with indirect coverage changes](https://codecov.io/gh/cloudwego/hertz/pull/687/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego)

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego)

</details>

[:umbrella: View full report in Codecov by Sentry](https://codecov.io/gh/cloudwego/hertz/pull/687?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).


Patch:
diff --git a/pkg/network/netpoll/dial.go b/pkg/network/netpoll/dial.go
index 86a371e..ee1feb0 100644
--- a/pkg/network/netpoll/dial.go
+++ b/pkg/network/netpoll/dial.go
@@ -45,6 +45,9 @@ func (d dialer) DialConnection(n, address string, timeout time.Duration, tlsConf
 }
 
 func (d dialer) DialTimeout(network, address string, timeout time.Duration, tlsConfig *tls.Config) (conn net.Conn, err error) {
+	if tlsConfig != nil {
+		return nil, errNotSupportTLS
+	}
 	conn, err = d.Dialer.DialTimeout(network, address, timeout)
 	return
 }


Test patch:
diff --git a/pkg/network/netpoll/dial_test.go b/pkg/network/netpoll/dial_test.go
index 1192253..1830d1e 100644
--- a/pkg/network/netpoll/dial_test.go
+++ b/pkg/network/netpoll/dial_test.go
@@ -65,5 +65,7 @@ func TestDial(t *testing.T) {
 		assert.DeepEqual(t, errNotSupportTLS, err)
 		_, err = dial.DialConnection("tcp", "localhost:10102", time.Microsecond, &tls.Config{})
 		assert.DeepEqual(t, errNotSupportTLS, err)
+		_, err = dial.DialTimeout("tcp", "localhost:10102", time.Microsecond, &tls.Config{})
+		assert.DeepEqual(t, errNotSupportTLS, err)
 	})
 }