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

Fixed: Remove data race around default dialer #6

Merged
merged 29 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
11fd40d
Use gorilla DialContext (#158)
juliens Aug 27, 2018
f6bbeac
Handle Te header when http2 (#157)
juliens Aug 27, 2018
77148e9
fix: buffer error and go1.11. (#159)
ldez Sep 4, 2018
fe51048
fix: use internal logger. (#160)
ldez Sep 21, 2018
2fe79cc
fix: body should never be nil (#162)
mmatur Oct 10, 2018
7d94d21
Pass host header for Websocket. (#163)
ldez Oct 10, 2018
ac21a76
fix: golint. (#165)
ldez Oct 19, 2018
c34b0c5
Flush when we have unannonced trailers (#168)
juliens Nov 30, 2018
0d102f4
add missing callback on close of hijacked connections (#175)
ravilr May 20, 2019
1bcd53a
Allowing sticky session's affinity cookies to be created with more op…
gheibia Jun 4, 2019
3d629cf
Ensuring the CookieOption struct's fields are exported (#179)
gheibia Jun 11, 2019
ba0780a
chore: migrate to go module. (#182)
ldez Aug 5, 2019
d063393
Update README.md
Mar 5, 2020
9dbd22c
feat: add more cookie options. (#195)
ldez Mar 21, 2020
1826c8c
Add Fallback setter on CircuitBreaker (#201)
sylr Jul 28, 2020
4738e10
review.
ldez Nov 6, 2020
e6b2784
Merge branch 'master' into patch-1
colynn Nov 6, 2020
b3cf989
Merge pull request #193 from colynn/patch-1
ldez Nov 6, 2020
764bd1e
doc: buffer.go: s/request/response/ (#172)
westurner Nov 6, 2020
9c50310
doc: typo fix /serveHTTP/serveWebSocket/s (#176)
benyanke Nov 6, 2020
577ef7a
Make the MakeRateError delay field public so that custom RateErrHandl…
somethingnew2-0 Nov 6, 2020
cd83df0
fix typo (#212)
imans777 Feb 8, 2021
31d475c
Fix panics on ratelimit period (division by zero) (#213)
Feb 23, 2021
6b5fc98
Bump to go1.16 (#214)
rtribotte Feb 26, 2021
99d4542
Add a mechanism to format the sticky cookie value (#216)
jbdoumenjou Apr 29, 2021
ebd6733
Merge remote-tracking branch 'upstream/master' into remove-data-race
May 28, 2021
598603a
Do not use global websocket.DefaultDialer
ckaznocha May 28, 2020
c675e78
Revert un-skipping test
ckaznocha May 28, 2020
d3e4a53
Update: Cleanup local and remote merged changes
May 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: go

go:
- 1.8.x
- 1.9.x
- 1.10.x

sudo: false
- 1.15.x
- 1.x

go_import_path: github.com/vulcand/oxy

Expand All @@ -14,12 +11,13 @@ notifications:
on_success: never
on_failure: change

env:
- GO111MODULE=on

before_install:
- go get -u github.com/golang/lint/golint
- go get -u github.com/client9/misspell/cmd/misspell
- 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 -
- chmod +x $GOPATH/bin/dep
- GO111MODULE=off go get -u golang.org/x/lint/golint
- GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell

install:
- make dependencies
- git diff --exit-code Gopkg.lock
- go mod tidy
- git diff --exit-code go.mod go.sum
168 changes: 0 additions & 168 deletions Gopkg.lock

This file was deleted.

47 changes: 0 additions & 47 deletions Gopkg.toml

This file was deleted.

5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: all

export GO111MODULE=on

PKGS := $(shell go list ./... | grep -v '/vendor/')
GOFILES := $(shell go list -f '{{range $$index, $$element := .GoFiles}}{{$$.Dir}}/{{$$element}}{{"\n"}}{{end}}' ./... | grep -v '/vendor/')
TXT_FILES := $(shell find * -type f -not -path 'vendor/**')
Expand All @@ -14,9 +16,6 @@ test: clean
test-verbose: clean
go test -v -race -cover $(PKGS)

dependencies:
dep ensure -v

clean:
find . -name flymake_* -delete
rm -f cover.out
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Oxy [![Build Status](https://travis-ci.org/vulcand/oxy.svg?branch=master)](https

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

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

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

Expand Down
23 changes: 15 additions & 8 deletions buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func MemRequestBodyBytes(m int64) optSetter {
}
}

// MaxResponseBodyBytes sets the maximum request body size in bytes
// MaxResponseBodyBytes sets the maximum response body size in bytes
func MaxResponseBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
Expand All @@ -190,7 +190,7 @@ func MaxResponseBodyBytes(m int64) optSetter {
}
}

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

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

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

func (b *bufferWriter) Write(buf []byte) (int, error) {
return b.buffer.Write(buf)
length, err := b.buffer.Write(buf)
if err != nil {
// Since go1.11 (https://github.com/golang/go/commit/8f38f28222abccc505b9a1992deecfe3e2cb85de)
// if the writer returns an error, the reverse proxy panics
b.log.Error(err)
length = len(buf)
}
return length, nil
}

// WriteHeader sets rw.Code.
Expand All @@ -410,7 +417,7 @@ func (b *bufferWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return conn, rw, err
}
b.log.Warningf("Upstream ResponseWriter of type %v does not implement http.Hijacker. Returning dummy channel.", reflect.TypeOf(b.responseWriter))
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))
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))
}

// SizeErrHandler Size error handler
Expand Down
Loading