Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
e377eeff
Commit
e377eeff
authored
Sep 23, 2017
by
Tw
Committed by
Matt Holt
Sep 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: websocket proxy exits immediately if backend is shutdown (#1869)
Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
84a2f8e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+34
-0
caddyhttp/proxy/reverseproxy.go
caddyhttp/proxy/reverseproxy.go
+13
-2
No files found.
caddyhttp/proxy/proxy_test.go
View file @
e377eeff
...
@@ -304,6 +304,40 @@ func TestWebSocketReverseProxyNonHijackerPanic(t *testing.T) {
...
@@ -304,6 +304,40 @@ func TestWebSocketReverseProxyNonHijackerPanic(t *testing.T) {
p
.
ServeHTTP
(
nonHijacker
,
r
)
p
.
ServeHTTP
(
nonHijacker
,
r
)
}
}
func
TestWebSocketReverseProxyBackendShutDown
(
t
*
testing
.
T
)
{
shutdown
:=
make
(
chan
struct
{})
backend
:=
httptest
.
NewServer
(
websocket
.
Handler
(
func
(
ws
*
websocket
.
Conn
)
{
shutdown
<-
struct
{}{}
}))
defer
backend
.
Close
()
go
func
()
{
<-
shutdown
backend
.
Close
()
}()
// Get proxy to use for the test
p
:=
newWebSocketTestProxy
(
backend
.
URL
,
false
)
backendProxy
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
p
.
ServeHTTP
(
w
,
r
)
}))
defer
backendProxy
.
Close
()
// Set up WebSocket client
url
:=
strings
.
Replace
(
backendProxy
.
URL
,
"http://"
,
"ws://"
,
1
)
ws
,
err
:=
websocket
.
Dial
(
url
,
""
,
backendProxy
.
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
ws
.
Close
()
var
actualMsg
string
if
rcvErr
:=
websocket
.
Message
.
Receive
(
ws
,
&
actualMsg
);
rcvErr
==
nil
{
t
.
Errorf
(
"we don't get backend shutdown notification"
)
}
}
func
TestWebSocketReverseProxyServeHTTPHandler
(
t
*
testing
.
T
)
{
func
TestWebSocketReverseProxyServeHTTPHandler
(
t
*
testing
.
T
)
{
// No-op websocket backend simply allows the WS connection to be
// No-op websocket backend simply allows the WS connection to be
// accepted then it will be immediately closed. Perfect for testing.
// accepted then it will be immediately closed. Perfect for testing.
...
...
caddyhttp/proxy/reverseproxy.go
View file @
e377eeff
...
@@ -320,8 +320,13 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
...
@@ -320,8 +320,13 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
}
}
defer
backendConn
.
Close
()
defer
backendConn
.
Close
()
proxyDone
:=
make
(
chan
struct
{},
2
)
// Proxy backend -> frontend.
// Proxy backend -> frontend.
go
pooledIoCopy
(
conn
,
backendConn
)
go
func
()
{
pooledIoCopy
(
conn
,
backendConn
)
proxyDone
<-
struct
{}{}
}()
// Proxy frontend -> backend.
// Proxy frontend -> backend.
//
//
...
@@ -336,7 +341,13 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
...
@@ -336,7 +341,13 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
backendConn
.
Write
(
rbuf
)
backendConn
.
Write
(
rbuf
)
}
}
}
}
pooledIoCopy
(
backendConn
,
conn
)
go
func
()
{
pooledIoCopy
(
backendConn
,
conn
)
proxyDone
<-
struct
{}{}
}()
// If one side is done, we are done.
<-
proxyDone
}
else
{
}
else
{
// NOTE:
// NOTE:
// Closing the Body involves acquiring a mutex, which is a
// Closing the Body involves acquiring a mutex, which is a
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment