Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b493bbb2
Unverified
Commit
b493bbb2
authored
Nov 26, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71419 from liggitt/backend-error-deadline
Set deadline for returning backend error
parents
3a2e1dff
f199f3d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
17 deletions
+22
-17
upgradeaware.go
...ng/src/k8s.io/apimachinery/pkg/util/proxy/upgradeaware.go
+22
-17
No files found.
staging/src/k8s.io/apimachinery/pkg/util/proxy/upgradeaware.go
View file @
b493bbb2
...
@@ -273,7 +273,7 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
...
@@ -273,7 +273,7 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
defer
backendConn
.
Close
()
defer
backendConn
.
Close
()
// determine the http response code from the backend by reading from rawResponse+backendConn
// determine the http response code from the backend by reading from rawResponse+backendConn
rawResponseCode
,
headerBytes
,
err
:=
getResponseCod
e
(
io
.
MultiReader
(
bytes
.
NewReader
(
rawResponse
),
backendConn
))
backendHTTPResponse
,
headerBytes
,
err
:=
getRespons
e
(
io
.
MultiReader
(
bytes
.
NewReader
(
rawResponse
),
backendConn
))
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
6
)
.
Infof
(
"Proxy connection error: %v"
,
err
)
klog
.
V
(
6
)
.
Infof
(
"Proxy connection error: %v"
,
err
)
h
.
Responder
.
Error
(
w
,
req
,
err
)
h
.
Responder
.
Error
(
w
,
req
,
err
)
...
@@ -300,6 +300,22 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
...
@@ -300,6 +300,22 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
}
}
defer
requestHijackedConn
.
Close
()
defer
requestHijackedConn
.
Close
()
if
backendHTTPResponse
.
StatusCode
!=
http
.
StatusSwitchingProtocols
{
// If the backend did not upgrade the request, echo the response from the backend to the client and return, closing the connection.
klog
.
V
(
6
)
.
Infof
(
"Proxy upgrade error, status code %d"
,
backendHTTPResponse
.
StatusCode
)
// set read/write deadlines
deadline
:=
time
.
Now
()
.
Add
(
10
*
time
.
Second
)
backendConn
.
SetReadDeadline
(
deadline
)
requestHijackedConn
.
SetWriteDeadline
(
deadline
)
// write the response to the client
err
:=
backendHTTPResponse
.
Write
(
requestHijackedConn
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"use of closed network connection"
)
{
klog
.
Errorf
(
"Error proxying data from backend to client: %v"
,
err
)
}
// Indicate we handled the request
return
true
}
// Forward raw response bytes back to client.
// Forward raw response bytes back to client.
if
len
(
rawResponse
)
>
0
{
if
len
(
rawResponse
)
>
0
{
klog
.
V
(
6
)
.
Infof
(
"Writing %d bytes to hijacked connection"
,
len
(
rawResponse
))
klog
.
V
(
6
)
.
Infof
(
"Writing %d bytes to hijacked connection"
,
len
(
rawResponse
))
...
@@ -308,17 +324,6 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
...
@@ -308,17 +324,6 @@ func (h *UpgradeAwareHandler) tryUpgrade(w http.ResponseWriter, req *http.Reques
}
}
}
}
if
rawResponseCode
!=
http
.
StatusSwitchingProtocols
{
// If the backend did not upgrade the request, finish echoing the response from the backend to the client and return, closing the connection.
klog
.
V
(
6
)
.
Infof
(
"Proxy upgrade error, status code %d"
,
rawResponseCode
)
_
,
err
:=
io
.
Copy
(
requestHijackedConn
,
backendConn
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"use of closed network connection"
)
{
klog
.
Errorf
(
"Error proxying data from backend to client: %v"
,
err
)
}
// Indicate we handled the request
return
true
}
// Proxy the connection. This is bidirectional, so we need a goroutine
// Proxy the connection. This is bidirectional, so we need a goroutine
// to copy in each direction. Once one side of the connection exits, we
// to copy in each direction. Once one side of the connection exits, we
// exit the function which performs cleanup and in the process closes
// exit the function which performs cleanup and in the process closes
...
@@ -380,17 +385,17 @@ func (h *UpgradeAwareHandler) DialForUpgrade(req *http.Request) (net.Conn, error
...
@@ -380,17 +385,17 @@ func (h *UpgradeAwareHandler) DialForUpgrade(req *http.Request) (net.Conn, error
return
dial
(
updatedReq
,
h
.
UpgradeTransport
)
return
dial
(
updatedReq
,
h
.
UpgradeTransport
)
}
}
// getResponseCode reads a http response from the given reader, returns the
status cod
e,
// getResponseCode reads a http response from the given reader, returns the
respons
e,
// the bytes read from the reader, and any error encountered
// the bytes read from the reader, and any error encountered
func
getResponse
Code
(
r
io
.
Reader
)
(
int
,
[]
byte
,
error
)
{
func
getResponse
(
r
io
.
Reader
)
(
*
http
.
Response
,
[]
byte
,
error
)
{
rawResponse
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
256
))
rawResponse
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
256
))
// Save the bytes read while reading the response headers into the rawResponse buffer
// Save the bytes read while reading the response headers into the rawResponse buffer
resp
,
err
:=
http
.
ReadResponse
(
bufio
.
NewReader
(
io
.
TeeReader
(
r
,
rawResponse
)),
nil
)
resp
,
err
:=
http
.
ReadResponse
(
bufio
.
NewReader
(
io
.
TeeReader
(
r
,
rawResponse
)),
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
nil
,
err
return
nil
,
nil
,
err
}
}
// return the http
status cod
e and the raw bytes consumed from the reader in the process
// return the http
respons
e and the raw bytes consumed from the reader in the process
return
resp
.
StatusCode
,
rawResponse
.
Bytes
(),
nil
return
resp
,
rawResponse
.
Bytes
(),
nil
}
}
// dial dials the backend at req.URL and writes req to it.
// dial dials the backend at req.URL and writes req to it.
...
...
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