From 3fab065d1f51c8f8ebb164badb4f234eeede1be1 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 7 Feb 2025 02:04:18 +0100 Subject: [PATCH] Migrate go code to function in go 1.22+ (#873) * Migrate go code to function in go 1.22+ * ci: attempt to bump golang from 1.19 to 1.23 in testing images --- .../workflows/build-publish-python-packages.yaml | 2 +- .github/workflows/test.yaml | 8 ++++---- continuous_integration/docker/base/Dockerfile | 7 +++++-- dask-gateway-server/dask-gateway-proxy/go.mod | 4 ++-- .../dask-gateway-proxy/pkg/sni/sni.go | 13 +++++++++++++ 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-publish-python-packages.yaml b/.github/workflows/build-publish-python-packages.yaml index c715bf9c..70bee529 100644 --- a/.github/workflows/build-publish-python-packages.yaml +++ b/.github/workflows/build-publish-python-packages.yaml @@ -68,7 +68,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: "1.21" + go-version: "1.23" cache-dependency-path: "**/*.sum" - uses: actions/setup-python@v5 with: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f62c2126..bb5584ec 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -58,13 +58,13 @@ jobs: # that would be fine. # - python-version: "3.10" - go-version: "1.20" + go-version: "1.22" - python-version: "3.11" - go-version: "1.20" + go-version: "1.22" - python-version: "3.12" - go-version: "1.21" + go-version: "1.23" - python-version: "3.13" - go-version: "1.21" + go-version: "1.23" steps: - uses: actions/checkout@v4 diff --git a/continuous_integration/docker/base/Dockerfile b/continuous_integration/docker/base/Dockerfile index 799e6555..74a37e18 100644 --- a/continuous_integration/docker/base/Dockerfile +++ b/continuous_integration/docker/base/Dockerfile @@ -8,7 +8,10 @@ FROM centos:7 ARG python_version="3.11" -ARG go_version="1.19" +# go_version was 1.19 until it was updated to 1.23.6 (2025-02-07) by adding a +# layer on top of the previous image, as it is no longer able to build and it +# was an easy way to update the golang version. +ARG go_version="1.23.6" # Set labels based on the Open Containers Initiative (OCI): # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys @@ -66,7 +69,7 @@ RUN yum install -y bzip2 \ && rm -rf /var/cache/yum # Install go -RUN curl -sL https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz \ +RUN curl -sL https://go.dev/dl/go${go_version}.linux-amd64.tar.gz \ | tar --extract --verbose --gzip --directory=/opt/ # Put Python and Go environments on PATH diff --git a/dask-gateway-server/dask-gateway-proxy/go.mod b/dask-gateway-server/dask-gateway-proxy/go.mod index 1bf49fc6..85c37067 100644 --- a/dask-gateway-server/dask-gateway-proxy/go.mod +++ b/dask-gateway-server/dask-gateway-proxy/go.mod @@ -1,8 +1,8 @@ module github.com/dask/dask-gateway/dask-gateway-proxy -go 1.21 +go 1.22 -require github.com/stretchr/testify v1.8.4 +require github.com/stretchr/testify v1.10.0 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/dask-gateway-server/dask-gateway-proxy/pkg/sni/sni.go b/dask-gateway-server/dask-gateway-proxy/pkg/sni/sni.go index 34c893c6..c326b031 100644 --- a/dask-gateway-server/dask-gateway-proxy/pkg/sni/sni.go +++ b/dask-gateway-server/dask-gateway-proxy/pkg/sni/sni.go @@ -8,6 +8,18 @@ import ( "net" ) +// hideWriteTo is a workaround introduced to make the code functional in 1.22+, +// where io.Copy would no longer make use of peekedTCPConn.Read after +// net.TCPConn.WriteTo was added, so the workaround is to hide it again. +// +// The workaround was developed inspecting: +// https://github.com/golang/go/commit/f664031bc17629080332a1c7bede38d67fd32e47 +// +type hideWriteTo struct{} +func (hideWriteTo) WriteTo(io.Writer) (int64, error) { + panic("can't happen") +} + type TcpConn interface { net.Conn CloseWrite() error @@ -16,6 +28,7 @@ type TcpConn interface { type peekedTCPConn struct { peeked []byte + hideWriteTo *net.TCPConn }