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

fix error reporting of timeout when getting invalid response, switch build to go 1.22.2 #914

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defaultEnv:
&defaultEnv
docker:
# specify the version
- image: docker.io/fortio/fortio.build:v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e
- image: docker.io/fortio/fortio.build:v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e
working_directory: /build/fortio

jobs:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binaries in larger image
FROM docker.io/fortio/fortio.build:v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e as build
FROM docker.io/fortio/fortio.build:v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e as build
WORKDIR /build
COPY --chown=build:build . fortio
ARG MODE=install
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dependencies and linters for build:
FROM golang:1.21.8@sha256:c82d4ad02c062cf2b393bf0374df26638c6fed3dfe52cdbd3635d4a7befab86e
FROM golang:1.22.2@sha256:c4fb952e712efd8f787bcd8e53fd66d1d83b7dc26adabc218e9eac1dbf776bdf
# Need gcc for -race test (and some linters though those work with CGO_ENABLED=0)
RUN apt-get -y update && \
apt-get --no-install-recommends -y upgrade && \
Expand All @@ -24,7 +24,7 @@ RUN set -x; if [ x"$(dpkg --print-architecture)" != x"s390x" ]; then \
# govulncheck
RUN go install golang.org/x/vuln/cmd/govulncheck@latest
WORKDIR /build
COPY .golangci.yml .
ADD https://raw.githubusercontent.com/fortio/workflows/main/golangci.yml .golangci.yml
VOLUME /build
RUN useradd -m build -d /build
RUN chown -R build:build /build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.echosrv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binaries in larger image
FROM docker.io/fortio/fortio.build:v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e as build
FROM docker.io/fortio/fortio.build:v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e as build
WORKDIR /build
COPY . fortio
RUN make -C fortio official-build-version BUILD_DIR=/build OFFICIAL_TARGET=fortio.org/fortio/echosrv
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.fcurl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binaries in larger image
FROM docker.io/fortio/fortio.build:v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e as build
FROM docker.io/fortio/fortio.build:v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e as build
WORKDIR /build
COPY . fortio
RUN make -C fortio official-build-version BUILD_DIR=/build OFFICIAL_TARGET=fortio.org/fortio/fcurl
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
IMAGES=echosrv fcurl # plus the combo image / Dockerfile without ext.

DOCKER_PREFIX := docker.io/fortio/fortio
BUILD_IMAGE_TAG := v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e
BUILD_IMAGE_TAG := v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e
BUILDX_PLATFORMS := linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
BUILDX_POSTFIX :=
ifeq '$(shell echo $(BUILDX_PLATFORMS) | awk -F "," "{print NF-1}")' '0'
Expand Down Expand Up @@ -68,7 +68,7 @@ local-lint: .golangci.yml
LINT_PACKAGES:=./...
lint: .golangci.yml
docker run -v $(CURDIR):/build/fortio $(BUILD_IMAGE) bash -c \
"cd /build/fortio \
"cd /build/fortio; chown build:build . \
&& time make local-lint DEBUG_LINTERS=\"$(DEBUG_LINTERS)\" LINT_PACKAGES=\"$(LINT_PACKAGES)\""

docker-test:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 1.63.5 -->
<!-- 1.63.6 -->
# Fortio

[![Awesome Go](https://fortio.org/mentioned-badge.svg)](https://github.com/avelino/awesome-go#networking)
Expand Down Expand Up @@ -60,13 +60,13 @@ You can install from source:
The [releases](https://github.com/fortio/fortio/releases) page has binaries for many OS/architecture combinations (see assets):

```shell
curl -L https://github.com/fortio/fortio/releases/download/v1.63.5/fortio-linux_amd64-1.63.5.tgz \
curl -L https://github.com/fortio/fortio/releases/download/v1.63.6/fortio-linux_amd64-1.63.6.tgz \
| sudo tar -C / -xvzpf -
# or the debian package
wget https://github.com/fortio/fortio/releases/download/v1.63.5/fortio_1.63.5_amd64.deb
dpkg -i fortio_1.63.5_amd64.deb
wget https://github.com/fortio/fortio/releases/download/v1.63.6/fortio_1.63.6_amd64.deb
dpkg -i fortio_1.63.6_amd64.deb
# or the rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.63.5/fortio-1.63.5-1.x86_64.rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.63.6/fortio-1.63.6-1.x86_64.rpm
# and more, see assets in release page
```

Expand All @@ -76,7 +76,7 @@ On a MacOS you can also install Fortio using [Homebrew](https://brew.sh/):
brew install fortio
```

On Windows, download https://github.com/fortio/fortio/releases/download/v1.63.5/fortio_win_1.63.5.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
On Windows, download https://github.com/fortio/fortio/releases/download/v1.63.6/fortio_win_1.63.6.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
```
fortio.exe server
```
Expand Down Expand Up @@ -130,7 +130,7 @@ Full list of command line flags (`fortio help`):
<!-- use release/updateFlags.sh to update this section -->
<pre>
<!-- USAGE_START -->
Φορτίο 1.63.5 usage:
Φορτίο 1.63.6 usage:
fortio command [flags] target
where command is one of: load (load testing), server (starts ui, rest api,
http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers),
Expand Down
2 changes: 1 addition & 1 deletion Webtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fi
PPROF_URL="$BASE_URL/debug/pprof/heap?debug=1"
$CURL "$PPROF_URL" | grep -i TotalAlloc # should find this in memory profile
# creating dummy container to hold a volume for test certs due to remote docker bind mount limitation.
DOCKERCURLID=$(docker run -d -v $TEST_CERT_VOL --net host --name $DOCKERSECVOLNAME docker.io/fortio/fortio.build:v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e sleep 120)
DOCKERCURLID=$(docker run -d -v $TEST_CERT_VOL --net host --name $DOCKERSECVOLNAME docker.io/fortio/fortio.build:v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e sleep 120)
# while we have something with actual curl binary do
# Test for h2c upgrade (#562)
docker exec $DOCKERSECVOLNAME /usr/bin/curl -v --http2 -m 10 -d foo42 http://localhost:8080/debug | tee >(cat 1>&2) | grep foo42
Expand Down
8 changes: 7 additions & 1 deletion fhttp/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,13 @@ func (c *FastClient) readResponse(conn net.Conn, reusedSocket bool) {
// handled below as possibly normal end of stream after we read something
break
}
log.S(log.Error, "Read error", log.Attr("err", err), log.Attr("size", c.size), log.Attr("dest", c.dest), log.Str("url", c.url),
errMsg := "Read error"
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
errMsg = "Timeout error (incomplete/invalid response)"
}
log.S(log.Error, errMsg, log.Attr("err", err), log.Attr("size", c.size), log.Attr("header_len", c.headerLen),
log.Attr("dest", c.dest), log.Str("url", c.url),
log.Attr("thread", c.id), log.Attr("run", c.runID))
c.code = SocketError
break
Expand Down
16 changes: 16 additions & 0 deletions fhttp/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,22 @@ func TestPayloadWithEchoBack(t *testing.T) {
}
}

// Exercise the code for https://github.com/fortio/fortio/pull/914
func TestReadtimeout(t *testing.T) {
// in theory we'd also redirect the log output to check we do see "Timeout error (incomplete/invalid response)"
// but the logger has its own tests and the switch from not covered to covered shows it's working/exercised by this test.
m, a := DynamicHTTPServer(false)
m.HandleFunc("/", EchoHandler)
url := fmt.Sprintf("http://localhost:%d/?delay=1s", a.Port)
opts := NewHTTPOptions(url)
opts.HTTPReqTimeOut = 100 * time.Millisecond
cli, _ := NewClient(opts)
code, _, _ := cli.Fetch(context.Background())
if code != -1 {
t.Errorf("Unexpected code %d", code)
}
}

// Test Post request with std client and the socket close after answering.
func TestPayloadWithStdClientAndClosedSocket(t *testing.T) {
m, a := DynamicHTTPServer(false)
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module fortio.org/fortio

go 1.19 // As a library the current version of fortio works with 1.18 (first version with generics) but tests use 1.19 features
// As a library the current version of fortio works with 1.18 (first version with generics) but tests use 1.19 features
// Note we will switch soon to 1.22 for the linters
go 1.19

// toolchain go1.22.2 // this shouldn't be necessary - see https://github.com/golang/go/issues/66175#issuecomment-2010343876

require (
fortio.org/assert v1.2.1
fortio.org/cli v1.5.2
fortio.org/dflag v1.7.1
fortio.org/log v1.12.1
fortio.org/log v1.12.2
fortio.org/scli v1.14.2
fortio.org/sets v1.0.4
fortio.org/testscript v0.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ fortio.org/cli v1.5.2 h1:MfEcHAhYyIkwG04/K1YJL946Y8/jyAjmF9WeR5ZG/5E=
fortio.org/cli v1.5.2/go.mod h1:SdQufh5PLd6oX2EtvtzLFw++gw8zVoejD1WlwGXAvYw=
fortio.org/dflag v1.7.1 h1:sDdYSw3py02awhgtWEtRtZvOM0UWgeDweRsXWROU3A0=
fortio.org/dflag v1.7.1/go.mod h1:3KB1SSilm1WwYl7gydDCnV24+DQaycAusNyy06dDD+c=
fortio.org/log v1.12.1 h1:8JNdFqOFbtifrdbqKkQZchGAoooLLr1J/tD2lYl1ZaI=
fortio.org/log v1.12.1/go.mod h1:1tMBG/Elr6YqjmJCWiejJp2FPvXg7/9UAN0Rfpkyt1o=
fortio.org/log v1.12.2 h1:JwLDFvEUKGfqA09fcf+mOn8kxsvwhjXV92xghxNnnwA=
fortio.org/log v1.12.2/go.mod h1:1tMBG/Elr6YqjmJCWiejJp2FPvXg7/9UAN0Rfpkyt1o=
fortio.org/scli v1.14.2 h1:dZEyzpC6YmCm24YSd2AvCAeMOxFEl7o4HvArFUpksIo=
fortio.org/scli v1.14.2/go.mod h1:5wwP5rS46H3vGoCWu5XaaDSH0f0OZnHJajgxR4E6fvs=
fortio.org/sets v1.0.4 h1:z5+qleG+9lpbpjGHvRGhfd+E5pJGsLetYl/w4pMc5MM=
Expand Down
2 changes: 1 addition & 1 deletion release/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Concatenated after ../Dockerfile to create the tgz
FROM docker.io/fortio/fortio.build:v69@sha256:c21ecd49fd232a4c184a04607f339c18d13151480aee779a047358f2f23e287e as stage
FROM docker.io/fortio/fortio.build:v70@sha256:a1a0c03170d4be21a94d62b7e0b5dd966135e8888e8b2bf97eb8511eb6ee778e as stage
ARG archs="amd64 arm64 ppc64le s390x"
ENV archs=${archs}
# Build image defaults to build user, switch back to root for
Expand Down