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
1d496a03
Commit
1d496a03
authored
Mar 25, 2015
by
Michal Fojtik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Suppress 'use of closed network connection' error in iowatcher
Signed-off-by:
Michal Fojtik
<
mfojtik@redhat.com
>
parent
159a58dd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
21 deletions
+55
-21
request.go
pkg/client/request.go
+3
-20
http.go
pkg/util/http.go
+46
-0
iowatcher.go
pkg/watch/iowatcher.go
+6
-1
No files found.
pkg/client/request.go
View file @
1d496a03
...
@@ -511,7 +511,9 @@ func (r *Request) Watch() (watch.Interface, error) {
...
@@ -511,7 +511,9 @@ func (r *Request) Watch() (watch.Interface, error) {
}
}
resp
,
err
:=
client
.
Do
(
req
)
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
if
isProbableEOF
(
err
)
{
// The watch stream mechanism handles many common partial data errors, so closed
// connections can be retried in many cases.
if
util
.
IsProbableEOF
(
err
)
{
return
watch
.
NewEmptyWatch
(),
nil
return
watch
.
NewEmptyWatch
(),
nil
}
}
return
nil
,
err
return
nil
,
err
...
@@ -525,25 +527,6 @@ func (r *Request) Watch() (watch.Interface, error) {
...
@@ -525,25 +527,6 @@ func (r *Request) Watch() (watch.Interface, error) {
return
watch
.
NewStreamWatcher
(
watchjson
.
NewDecoder
(
resp
.
Body
,
r
.
codec
)),
nil
return
watch
.
NewStreamWatcher
(
watchjson
.
NewDecoder
(
resp
.
Body
,
r
.
codec
)),
nil
}
}
// isProbableEOF returns true if the given error resembles a connection termination
// scenario that would justify assuming that the watch is empty. The watch stream
// mechanism handles many common partial data errors, so closed connections can be
// retried in many cases.
func
isProbableEOF
(
err
error
)
bool
{
if
uerr
,
ok
:=
err
.
(
*
url
.
Error
);
ok
{
err
=
uerr
.
Err
}
switch
{
case
err
==
io
.
EOF
:
return
true
case
err
.
Error
()
==
"http: can't write HTTP request on broken connection"
:
return
true
case
strings
.
Contains
(
err
.
Error
(),
"connection reset by peer"
)
:
return
true
}
return
false
}
// Stream formats and executes the request, and offers streaming of the response.
// Stream formats and executes the request, and offers streaming of the response.
// Returns io.ReadCloser which could be used for streaming of the response, or an error
// Returns io.ReadCloser which could be used for streaming of the response, or an error
// Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object.
// Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object.
...
...
pkg/util/http.go
0 → 100644
View file @
1d496a03
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"io"
"net/url"
"strings"
)
// IsProbableEOF returns true if the given error resembles a connection termination
// scenario that would justify assuming that the watch is empty.
// These errors are what the Go http stack returns back to us which are general
// connection closure errors (strongly correlated) and callers that need to
// differentiate probable errors in connection behavior between normal "this is
// disconnected" should use the method.
func
IsProbableEOF
(
err
error
)
bool
{
if
uerr
,
ok
:=
err
.
(
*
url
.
Error
);
ok
{
err
=
uerr
.
Err
}
switch
{
case
err
==
io
.
EOF
:
return
true
case
err
.
Error
()
==
"http: can't write HTTP request on broken connection"
:
return
true
case
strings
.
Contains
(
err
.
Error
(),
"connection reset by peer"
)
:
return
true
case
strings
.
Contains
(
strings
.
ToLower
(
err
.
Error
()),
"use of closed network connection"
)
:
return
true
}
return
false
}
pkg/watch/iowatcher.go
View file @
1d496a03
...
@@ -101,7 +101,12 @@ func (sw *StreamWatcher) receive() {
...
@@ -101,7 +101,12 @@ func (sw *StreamWatcher) receive() {
case
io
.
ErrUnexpectedEOF
:
case
io
.
ErrUnexpectedEOF
:
glog
.
V
(
1
)
.
Infof
(
"Unexpected EOF during watch stream event decoding: %v"
,
err
)
glog
.
V
(
1
)
.
Infof
(
"Unexpected EOF during watch stream event decoding: %v"
,
err
)
default
:
default
:
glog
.
Errorf
(
"Unable to decode an event from the watch stream: %v"
,
err
)
msg
:=
"Unable to decode an event from the watch stream: %v"
if
util
.
IsProbableEOF
(
err
)
{
glog
.
V
(
5
)
.
Infof
(
msg
,
err
)
}
else
{
glog
.
Errorf
(
msg
,
err
)
}
}
}
return
return
}
}
...
...
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