Skip to content

Commit 977a6d8

Browse files
itsai220Eric Powersjuliensldezmmatur
authored
Fixed: Remove data race around default dialer (#6) (#9)
* Use gorilla DialContext (vulcand#158) * Handle Te header when http2 (vulcand#157) * fix: buffer error and go1.11. (vulcand#159) * fix: buffer error and go1.11. * chore: add go1.11 in Travis. * review: comment. * fix: use internal logger. (vulcand#160) * fix: body should never be nil (vulcand#162) * Pass host header for Websocket. (vulcand#163) * feat: pass host header for Websocket. * add tests. * fix: golint. (vulcand#165) * Flush when we have unannonced trailers (vulcand#168) * Flush when we have unannonced trailers * Remove 1.8, not supported in golint anymore * add missing callback on close of hijacked connections (vulcand#175) * Allowing sticky session's affinity cookies to be created with more options such as HttpOnly or Secure (vulcand#174) * Ensuring the CookieOption struct's fields are exported (vulcand#179) * ensuring the CookieOption struct's fields are exported (vulcand#174) * dep ensuring * Updating failing test, I should pay more attention * dep ensuring has caused problems, reverting. Although this is really strange that dep should do this * chore: migrate to go module. (vulcand#182) * Update README.md Go library change godoc to "pkg.go.dev" * feat: add more cookie options. (vulcand#195) * chore: update dependencies. * feat: add more cookie options. * chore: update travis configuration. * Add Fallback setter on CircuitBreaker (vulcand#201) Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr> * review. * doc: buffer.go: s/request/response/ (vulcand#172) * doc: typo fix /serveHTTP/serveWebSocket/s (vulcand#176) * Make the MakeRateError delay field public so that custom RateErrHandlers can be more easily written (vulcand#206) * fix typo (vulcand#212) * Fix panics on ratelimit period (division by zero) (vulcand#213) * Bump to go1.16 (vulcand#214) * Add a mechanism to format the sticky cookie value (vulcand#216) Co-authored-by: Tom Moulard <tom.moulard@traefik.io> Co-authored-by: M <m@cognusion.com> Co-authored-by: Sylvain Rabot <sylvain@abstraction.fr> * Do not use global websocket.DefaultDialer This change makes it so that each forward gets its own dialer rather then all sharing the global `websocket.DefaultDialer`. It fixes the flaky `TestWebSocketNumGoRoutine` test and allows `WebsocketTLSClientConfig` to set a different TLS config than the one used in the http `RoundTripper`, the TLS config in the http `RoundTripper` will still be used as a fallback if one wasn't set by the user. Adds the new `optSetter` `WebsocketNetDialContext` to set a custom DialContet for WebSocket use. - `go test -run=TestWebSocketNumGoRoutine -count=100 ./forward` now passes. Removed the skip directive. - Closes vulcand#199 - Closes vulcand#125 * Revert un-skipping test * Update: Cleanup local and remote merged changes Co-authored-by: SALLEYRON Julien <julien.salleyron@gmail.com> Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com> Co-authored-by: Michael <mmatur@users.noreply.github.com> Co-authored-by: ravilr <raviprasad_lr@yahoo.com> Co-authored-by: Amir Keibi <gheibia@users.noreply.github.com> Co-authored-by: colynn.liu <colynnliu@foxmail.com> Co-authored-by: Sylvain Rabot <sylvain@abstraction.fr> Co-authored-by: Fernandez Ludovic <lfernandez.dev@gmail.com> Co-authored-by: colynn.liu <colynn.liu@gmail.com> Co-authored-by: Wes Turner <50891+westurner@users.noreply.github.com> Co-authored-by: Ben Yanke <ben@benyanke.com> Co-authored-by: Peter C <somethingnew2-0@users.noreply.github.com> Co-authored-by: Iman Sahebi <iman.s_sani@yahoo.com> Co-authored-by: Douglas De Toni Machado <douglas.machado@traefik.io> Co-authored-by: Romain <rtribotte@users.noreply.github.com> Co-authored-by: Jean-Baptiste Doumenjou <925513+jbdoumenjou@users.noreply.github.com> Co-authored-by: Tom Moulard <tom.moulard@traefik.io> Co-authored-by: M <m@cognusion.com> Co-authored-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com> Co-authored-by: Clifton Kaznocha <ckaznocha@gmail.com> Co-authored-by: Eric Powers <epowers@paloaltonetworks.com> Co-authored-by: SALLEYRON Julien <julien.salleyron@gmail.com> Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com> Co-authored-by: Michael <mmatur@users.noreply.github.com> Co-authored-by: ravilr <raviprasad_lr@yahoo.com> Co-authored-by: Amir Keibi <gheibia@users.noreply.github.com> Co-authored-by: colynn.liu <colynnliu@foxmail.com> Co-authored-by: Sylvain Rabot <sylvain@abstraction.fr> Co-authored-by: Fernandez Ludovic <lfernandez.dev@gmail.com> Co-authored-by: colynn.liu <colynn.liu@gmail.com> Co-authored-by: Wes Turner <50891+westurner@users.noreply.github.com> Co-authored-by: Ben Yanke <ben@benyanke.com> Co-authored-by: Peter C <somethingnew2-0@users.noreply.github.com> Co-authored-by: Iman Sahebi <iman.s_sani@yahoo.com> Co-authored-by: Douglas De Toni Machado <douglas.machado@traefik.io> Co-authored-by: Romain <rtribotte@users.noreply.github.com> Co-authored-by: Jean-Baptiste Doumenjou <925513+jbdoumenjou@users.noreply.github.com> Co-authored-by: Tom Moulard <tom.moulard@traefik.io> Co-authored-by: M <m@cognusion.com> Co-authored-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com> Co-authored-by: Clifton Kaznocha <ckaznocha@gmail.com>
1 parent 99b7071 commit 977a6d8

31 files changed

+1459
-362
lines changed

.travis.yml

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
language: go
22

33
go:
4-
- 1.8.x
5-
- 1.9.x
6-
- 1.10.x
7-
8-
sudo: false
4+
- 1.15.x
5+
- 1.x
96

107
go_import_path: github.com/vulcand/oxy
118

@@ -14,12 +11,13 @@ notifications:
1411
on_success: never
1512
on_failure: change
1613

14+
env:
15+
- GO111MODULE=on
16+
1717
before_install:
18-
- go get -u github.com/golang/lint/golint
19-
- go get -u github.com/client9/misspell/cmd/misspell
20-
- curl -sI https://github.com/golang/dep/releases/latest | grep -Fi Location | tr -d '\r' | sed "s/tag/download/g" | awk -F " " '{ print $2 "/dep-linux-amd64"}' | wget --output-document=$GOPATH/bin/dep -i -
21-
- chmod +x $GOPATH/bin/dep
18+
- GO111MODULE=off go get -u golang.org/x/lint/golint
19+
- GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
2220

2321
install:
24-
- make dependencies
25-
- git diff --exit-code Gopkg.lock
22+
- go mod tidy
23+
- git diff --exit-code go.mod go.sum

Gopkg.lock

-168
This file was deleted.

Gopkg.toml

-48
This file was deleted.

Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.PHONY: all
22

3+
export GO111MODULE=on
4+
35
PKGS := $(shell go list ./... | grep -v '/vendor/')
46
GOFILES := $(shell go list -f '{{range $$index, $$element := .GoFiles}}{{$$.Dir}}/{{$$element}}{{"\n"}}{{end}}' ./... | grep -v '/vendor/')
57
TXT_FILES := $(shell find * -type f -not -path 'vendor/**')
@@ -14,9 +16,6 @@ test: clean
1416
test-verbose: clean
1517
go test -v -race -cover $(PKGS)
1618

17-
dependencies:
18-
dep ensure -v
19-
2019
clean:
2120
find . -name flymake_* -delete
2221
rm -f cover.out

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Oxy [![Build Status](https://travis-ci.org/vulcand/oxy.svg?branch=master)](https
33

44
Oxy is a Go library with HTTP handlers that enhance HTTP standard library:
55

6-
* [Buffer](http://godoc.org/github.com/vulcand/oxy/buffer) retries and buffers requests and responses
7-
* [Stream](http://godoc.org/github.com/vulcand/oxy/stream) passes-through requests, supports chunked encoding with configurable flush interval
8-
* [Forward](http://godoc.org/github.com/vulcand/oxy/forward) forwards requests to remote location and rewrites headers
9-
* [Roundrobin](http://godoc.org/github.com/vulcand/oxy/roundrobin) is a round-robin load balancer
10-
* [Circuit Breaker](http://godoc.org/github.com/vulcand/oxy/cbreaker) Hystrix-style circuit breaker
11-
* [Connlimit](http://godoc.org/github.com/vulcand/oxy/connlimit) Simultaneous connections limiter
12-
* [Ratelimit](http://godoc.org/github.com/vulcand/oxy/ratelimit) Rate limiter (based on tokenbucket algo)
13-
* [Trace](http://godoc.org/github.com/vulcand/oxy/trace) Structured request and response logger
6+
* [Buffer](https://pkg.go.dev/github.com/vulcand/oxy/buffer) retries and buffers requests and responses
7+
* [Stream](https://pkg.go.dev/github.com/vulcand/oxy/stream) passes-through requests, supports chunked encoding with configurable flush interval
8+
* [Forward](https://pkg.go.dev/github.com/vulcand/oxy/forward) forwards requests to remote location and rewrites headers
9+
* [Roundrobin](https://pkg.go.dev/github.com/vulcand/oxy/roundrobin) is a round-robin load balancer
10+
* [Circuit Breaker](https://pkg.go.dev/github.com/vulcand/oxy/cbreaker) Hystrix-style circuit breaker
11+
* [Connlimit](https://pkg.go.dev/github.com/vulcand/oxy/connlimit) Simultaneous connections limiter
12+
* [Ratelimit](https://pkg.go.dev/github.com/vulcand/oxy/ratelimit) Rate limiter (based on tokenbucket algo)
13+
* [Trace](https://pkg.go.dev/github.com/vulcand/oxy/trace) Structured request and response logger
1414

1515
It is designed to be fully compatible with http standard library, easy to customize and reuse.
1616

buffer/buffer.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func MemRequestBodyBytes(m int64) optSetter {
179179
}
180180
}
181181

182-
// MaxResponseBodyBytes sets the maximum request body size in bytes
182+
// MaxResponseBodyBytes sets the maximum response body size in bytes
183183
func MaxResponseBodyBytes(m int64) optSetter {
184184
return func(b *Buffer) error {
185185
if m < 0 {
@@ -190,7 +190,7 @@ func MaxResponseBodyBytes(m int64) optSetter {
190190
}
191191
}
192192

193-
// MemResponseBodyBytes sets the maximum request body to be stored in memory
193+
// MemResponseBodyBytes sets the maximum response body to be stored in memory
194194
// buffer middleware will serialize the excess to disk.
195195
func MemResponseBodyBytes(m int64) optSetter {
196196
return func(b *Buffer) error {
@@ -216,7 +216,7 @@ func (b *Buffer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
216216
}
217217

218218
if err := b.checkLimit(req); err != nil {
219-
log.Errorf("vulcand/oxy/buffer: request body over limit, err: %v", err)
219+
b.log.Errorf("vulcand/oxy/buffer: request body over limit, err: %v", err)
220220
b.errHandler.ServeHTTP(w, req, err)
221221
return
222222
}
@@ -234,12 +234,12 @@ func (b *Buffer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
234234

235235
// Set request body to buffered reader that can replay the read and execute Seek
236236
// Note that we don't change the original request body as it's handled by the http server
237-
// and we don'w want to mess with standard library
237+
// and we don't want to mess with standard library
238238
defer func() {
239239
if body != nil {
240240
errClose := body.Close()
241241
if errClose != nil {
242-
log.Errorf("vulcand/oxy/buffer: failed to close body, err: %v", errClose)
242+
b.log.Errorf("vulcand/oxy/buffer: failed to close body, err: %v", errClose)
243243
}
244244
}
245245
}()
@@ -330,7 +330,7 @@ func (b *Buffer) copyRequest(req *http.Request, body io.ReadCloser, bodySize int
330330
o.TransferEncoding = []string{}
331331
// http.Transport will close the request body on any error, we are controlling the close process ourselves, so we override the closer here
332332
if body == nil {
333-
o.Body = nil
333+
o.Body = ioutil.NopCloser(req.Body)
334334
} else {
335335
o.Body = ioutil.NopCloser(body.(io.Reader))
336336
}
@@ -383,7 +383,14 @@ func (b *bufferWriter) Header() http.Header {
383383
}
384384

385385
func (b *bufferWriter) Write(buf []byte) (int, error) {
386-
return b.buffer.Write(buf)
386+
length, err := b.buffer.Write(buf)
387+
if err != nil {
388+
// Since go1.11 (https://github.com/golang/go/commit/8f38f28222abccc505b9a1992deecfe3e2cb85de)
389+
// if the writer returns an error, the reverse proxy panics
390+
b.log.Error(err)
391+
length = len(buf)
392+
}
393+
return length, nil
387394
}
388395

389396
// WriteHeader sets rw.Code.
@@ -410,7 +417,7 @@ func (b *bufferWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
410417
return conn, rw, err
411418
}
412419
b.log.Warningf("Upstream ResponseWriter of type %v does not implement http.Hijacker. Returning dummy channel.", reflect.TypeOf(b.responseWriter))
413-
return nil, nil, fmt.Errorf("The response writer that was wrapped in this proxy, does not implement http.Hijacker. It is of type: %v", reflect.TypeOf(b.responseWriter))
420+
return nil, nil, fmt.Errorf("the response writer wrapped in this proxy does not implement http.Hijacker. Its type is: %v", reflect.TypeOf(b.responseWriter))
414421
}
415422

416423
// SizeErrHandler Size error handler

0 commit comments

Comments
 (0)