Skip to content

Commit

Permalink
Fixed: Remove data race around default dialer (#6) (#9)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: M <[email protected]>
Co-authored-by: Sylvain Rabot <[email protected]>

* 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 <[email protected]>
Co-authored-by: Ludovic Fernandez <[email protected]>
Co-authored-by: Michael <[email protected]>
Co-authored-by: ravilr <[email protected]>
Co-authored-by: Amir Keibi <[email protected]>
Co-authored-by: colynn.liu <[email protected]>
Co-authored-by: Sylvain Rabot <[email protected]>
Co-authored-by: Fernandez Ludovic <[email protected]>
Co-authored-by: colynn.liu <[email protected]>
Co-authored-by: Wes Turner <[email protected]>
Co-authored-by: Ben Yanke <[email protected]>
Co-authored-by: Peter C <[email protected]>
Co-authored-by: Iman Sahebi <[email protected]>
Co-authored-by: Douglas De Toni Machado <[email protected]>
Co-authored-by: Romain <[email protected]>
Co-authored-by: Jean-Baptiste Doumenjou <[email protected]>
Co-authored-by: Tom Moulard <[email protected]>
Co-authored-by: M <[email protected]>
Co-authored-by: Clifton Kaznocha <[email protected]>
Co-authored-by: Clifton Kaznocha <[email protected]>

Co-authored-by: Eric Powers <[email protected]>
Co-authored-by: SALLEYRON Julien <[email protected]>
Co-authored-by: Ludovic Fernandez <[email protected]>
Co-authored-by: Michael <[email protected]>
Co-authored-by: ravilr <[email protected]>
Co-authored-by: Amir Keibi <[email protected]>
Co-authored-by: colynn.liu <[email protected]>
Co-authored-by: Sylvain Rabot <[email protected]>
Co-authored-by: Fernandez Ludovic <[email protected]>
Co-authored-by: colynn.liu <[email protected]>
Co-authored-by: Wes Turner <[email protected]>
Co-authored-by: Ben Yanke <[email protected]>
Co-authored-by: Peter C <[email protected]>
Co-authored-by: Iman Sahebi <[email protected]>
Co-authored-by: Douglas De Toni Machado <[email protected]>
Co-authored-by: Romain <[email protected]>
Co-authored-by: Jean-Baptiste Doumenjou <[email protected]>
Co-authored-by: Tom Moulard <[email protected]>
Co-authored-by: M <[email protected]>
Co-authored-by: Clifton Kaznocha <[email protected]>
Co-authored-by: Clifton Kaznocha <[email protected]>
  • Loading branch information
22 people authored Jul 13, 2021
1 parent 99b7071 commit 977a6d8
Show file tree
Hide file tree
Showing 31 changed files with 1,459 additions and 362 deletions.
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.

48 changes: 0 additions & 48 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

0 comments on commit 977a6d8

Please sign in to comment.