Skip to content
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

cmd/commandfuncs: use net.ErrClosed instead of doing substring error checks [requires go 1.16] #3805

Closed
jimen0 opened this issue Oct 18, 2020 · 8 comments

Comments

@jimen0
Copy link
Contributor

jimen0 commented Oct 18, 2020

Go 1.16 will introduce a new exported net.ErrClosed (see this issue for context) error allowing Caddy to properly check for this error instead of using the substring matching hack.

Current code:

caddy/cmd/commandfuncs.go

Lines 115 to 123 in 385adf5

go func() {
for {
conn, err := ln.Accept()
if err != nil {
if !strings.Contains(err.Error(), "use of closed network connection") {
log.Println(err)
}
break
}

Proposed patch once Caddy starts using go 1.16:

diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go
index 772fe012..36c686c5 100644
--- a/cmd/commandfuncs.go
+++ b/cmd/commandfuncs.go
@@ -19,6 +19,7 @@ import (
 	"context"
 	"crypto/rand"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"io"
 	"io/ioutil"
@@ -116,7 +117,7 @@ func cmdStart(fl Flags) (int, error) {
 		for {
 			conn, err := ln.Accept()
 			if err != nil {
-				if !strings.Contains(err.Error(), "use of closed network connection") {
+				if !errors.Is(err, net.ErrClosed) {
 					log.Println(err)
 				}
 				break

Please, let me know what do you think about it and, if you would prefer me to open the PR now or if I should wait for 1.16 to be released. Also, please feel free to close this issue if you don't think we need this code change.

Best,
Miguel

@jimen0 jimen0 changed the title cmd/commandfuncs: use net.ErrClosed instead of doing a substring error check [requires go 1.16] cmd/commandfuncs: use net.ErrClosed instead of doing a substring error checks [requires go 1.16] Oct 18, 2020
@jimen0 jimen0 changed the title cmd/commandfuncs: use net.ErrClosed instead of doing a substring error checks [requires go 1.16] cmd/commandfuncs: use net.ErrClosed instead of doing substring error checks [requires go 1.16] Oct 18, 2020
@francislavoie
Copy link
Member

This is interesting, but I'm not sure we can realistically make this change soon if it will require us to bump up the minimum Go version. We want to keep a reasonably low minimum version to maintain compatibility with the Go version used by the different platforms we support, e.g. Fedora/Centos.

Probably best to wait a couple more versions to let the ecosystem to catch up before we bump minimum.

@francislavoie francislavoie added deferred ⏰ We'll come back to this later optimization 📉 Performance or cost improvements labels Nov 1, 2020
@mholt mholt removed the optimization 📉 Performance or cost improvements label Nov 2, 2020
@jimen0
Copy link
Contributor Author

jimen0 commented Jun 11, 2021

Hi @mholt @francislavoie 1.17beta1 is out. Should I prepare the PR and submit it once 1.17 is out or would you prefer me waiting until 1.18 is released? 😄

@francislavoie
Copy link
Member

Thanks for the reminder @jimen0!

We're keeping an eye on https://src.fedoraproject.org/rpms/golang and https://access.redhat.com/support/policy/updates/rhel8-app-streams-life-cycle (bottom of the page) to see what their supported Go versions are. Since 1.16 isn't supported across the board yet, I think we'll wait a bit longer.

We could bump the mimimum regardless, but it would take the COPR maintainers a bit of extra work to wire up the Caddy package to use a later version than their default.

/cc @carlwgeorge, who informed me of the above details 👍

@carlwgeorge
Copy link
Contributor

Right now the problematic distros are Fedora 33, RHEL 7, and RHEL 8. RHEL 8 will get golang 1.16 approximately in November. Fedora 33 will be EOL about the same time so it won't be a concern either at that point. I haven't heard anything about golang getting upgraded past 1.15 for RHEL 7 (which comes from the community EPEL repo), but if that's the last one that is an issue we can do the necessary override in our COPR build root. If waiting until November is unacceptable, we'll set up the overrides for all of them.

@jimen0
Copy link
Contributor Author

jimen0 commented Jun 13, 2021

From my side this can wait as much as needed. It's just code cleanup and not something urgent. I'll set up a reminder for mid-November to come back to this PR. Thank you a lot for your time @carlwgeorge. This is what makes opensource so awesome!

@francislavoie
Copy link
Member

FYI @jimen0 we're readying to bump to 1.16 very soon #4283

@jimen0
Copy link
Contributor Author

jimen0 commented Aug 18, 2021

Thanks for the ping @francislavoie! My calendar was marked for November. I submitted the PR.

No rush to review it at all. Let me know if anything else is needed from my side and happy 1.17 migration!

@mholt
Copy link
Member

mholt commented Aug 18, 2021

Yeah sorry it's early; I thought November would be the release date, but I guess not.

mholt pushed a commit that referenced this issue Aug 18, 2021
@mholt mholt closed this as completed Aug 18, 2021
@mholt mholt removed the deferred ⏰ We'll come back to this later label Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants