Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
a67b44ea
Commit
a67b44ea
authored
4 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Slight improvement in error logging
parent
2f7945b3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
node/http.go
+3
-3
3 additions, 3 deletions
node/http.go
node/proxy.go
+11
-10
11 additions, 10 deletions
node/proxy.go
with
14 additions
and
13 deletions
node/http.go
+
3
−
3
View file @
a67b44ea
...
@@ -141,7 +141,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h
...
@@ -141,7 +141,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h
mountPath
:=
strings
.
TrimSuffix
(
r
.
URL
.
Path
,
".m3u"
)
mountPath
:=
strings
.
TrimSuffix
(
r
.
URL
.
Path
,
".m3u"
)
mount
,
ok
:=
n
.
mounts
.
GetMount
(
mountPath
)
mount
,
ok
:=
n
.
mounts
.
GetMount
(
mountPath
)
if
!
ok
{
if
!
ok
{
log
.
Printf
(
"http: %s: not found"
,
mountPath
)
//
log.Printf("http: %s:
mount point
not found", mountPath)
http
.
NotFound
(
w
,
r
)
http
.
NotFound
(
w
,
r
)
return
return
}
}
...
@@ -152,7 +152,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h
...
@@ -152,7 +152,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h
func
serveSource
(
n
*
Node
,
mount
*
pb
.
Mount
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
serveSource
(
n
*
Node
,
mount
*
pb
.
Mount
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// Can't connect sources to relay streams.
// Can't connect sources to relay streams.
if
mount
.
IsRelay
()
{
if
mount
.
IsRelay
()
{
log
.
Printf
(
"source connection to relay stream %s"
,
mount
.
Path
)
log
.
Printf
(
"
error:
source connection to relay stream %s"
,
mount
.
Path
)
http
.
Error
(
w
,
"Stream is relayed, no source connections allowed"
,
http
.
StatusBadRequest
)
http
.
Error
(
w
,
"Stream is relayed, no source connections allowed"
,
http
.
StatusBadRequest
)
return
return
}
}
...
@@ -184,7 +184,7 @@ func serveRedirect(lb *loadBalancer, mount *pb.Mount, w http.ResponseWriter, r *
...
@@ -184,7 +184,7 @@ func serveRedirect(lb *loadBalancer, mount *pb.Mount, w http.ResponseWriter, r *
// 1:1 mapping between Icecasts and frontends.
// 1:1 mapping between Icecasts and frontends.
targetNode
:=
lb
.
chooseNode
(
&
httpRequestContext
{
r
})
targetNode
:=
lb
.
chooseNode
(
&
httpRequestContext
{
r
})
if
targetNode
==
nil
{
if
targetNode
==
nil
{
log
.
Printf
(
"http: %s: no nodes available"
,
mount
.
Path
)
log
.
Printf
(
"
error:
http: %s: no nodes available"
,
mount
.
Path
)
http
.
Error
(
w
,
"No nodes available"
,
http
.
StatusServiceUnavailable
)
http
.
Error
(
w
,
"No nodes available"
,
http
.
StatusServiceUnavailable
)
return
return
}
}
...
...
This diff is collapsed.
Click to expand it.
node/proxy.go
+
11
−
10
View file @
a67b44ea
...
@@ -64,7 +64,7 @@ type wrappedWriter interface {
...
@@ -64,7 +64,7 @@ type wrappedWriter interface {
// request. The additional streamName parameter is used for
// request. The additional streamName parameter is used for
// instrumentation.
// instrumentation.
func
doIcecastProxy
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
,
target
*
url
.
URL
,
streamName
string
)
{
func
doIcecastProxy
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
,
target
*
url
.
URL
,
streamName
string
)
{
log
.
Printf
(
"proxy: in=%s out=%s stream=%s"
,
req
.
URL
.
String
(),
target
.
String
(),
streamName
)
//
log.Printf("proxy: in=%s out=%s stream=%s", req.URL.String(), target.String(), streamName)
outreq
:=
new
(
http
.
Request
)
outreq
:=
new
(
http
.
Request
)
*
outreq
=
*
req
// includes shallow copies of maps, but okay
*
outreq
=
*
req
// includes shallow copies of maps, but okay
...
@@ -119,7 +119,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
...
@@ -119,7 +119,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
// to it.
// to it.
upstream
,
err
:=
dialer
.
Dial
(
"tcp"
,
outreq
.
URL
.
Host
)
upstream
,
err
:=
dialer
.
Dial
(
"tcp"
,
outreq
.
URL
.
Host
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"http: proxy dial error: %v"
,
err
)
log
.
Printf
(
"
error:
http: proxy dial error: %v"
,
err
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
proxyConnectErrs
.
WithLabelValues
(
streamName
,
target
.
Host
)
.
Inc
()
proxyConnectErrs
.
WithLabelValues
(
streamName
,
target
.
Host
)
.
Inc
()
return
return
...
@@ -130,7 +130,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
...
@@ -130,7 +130,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
// stuck on unresponsive TCP servers.
// stuck on unresponsive TCP servers.
upstream
.
SetDeadline
(
time
.
Now
()
.
Add
(
requestWriteTimeout
))
// nolint: errcheck
upstream
.
SetDeadline
(
time
.
Now
()
.
Add
(
requestWriteTimeout
))
// nolint: errcheck
if
err
:=
outreq
.
Write
(
upstream
);
err
!=
nil
{
if
err
:=
outreq
.
Write
(
upstream
);
err
!=
nil
{
log
.
Printf
(
"http: proxy request write error: %v"
,
err
)
log
.
Printf
(
"
error:
http: proxy request write error: %v"
,
err
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
proxyConnectErrs
.
WithLabelValues
(
streamName
,
target
.
Host
)
.
Inc
()
proxyConnectErrs
.
WithLabelValues
(
streamName
,
target
.
Host
)
.
Inc
()
return
return
...
@@ -147,7 +147,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
...
@@ -147,7 +147,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
var
err
error
var
err
error
conn
,
_
,
err
=
h
.
Hijack
()
conn
,
_
,
err
=
h
.
Hijack
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"http: proxy hijack error: %v"
,
err
)
log
.
Printf
(
"
error:
http: proxy hijack error: %v"
,
err
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
rw
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
return
}
}
...
@@ -159,13 +159,13 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
...
@@ -159,13 +159,13 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
}
}
}
}
if
conn
==
nil
{
if
conn
==
nil
{
log
.
Printf
(
"http: proxy error: could not find hijackable connection"
)
log
.
Printf
(
"
error:
http: proxy error: could not find hijackable connection"
)
http
.
Error
(
rw
,
"could not find hijackable connection"
,
http
.
StatusInternalServerError
)
http
.
Error
(
rw
,
"could not find hijackable connection"
,
http
.
StatusInternalServerError
)
return
return
}
}
defer
conn
.
Close
()
defer
conn
.
Close
()
if
err
:=
conn
.
SetDeadline
(
time
.
Time
{});
err
!=
nil
{
if
err
:=
conn
.
SetDeadline
(
time
.
Time
{});
err
!=
nil
{
log
.
Printf
(
"http: proxy setdeadline error: %v"
,
err
)
log
.
Printf
(
"
error:
http: proxy setdeadline error: %v"
,
err
)
}
}
// Run two-way proxying.
// Run two-way proxying.
...
@@ -190,16 +190,17 @@ func copyStream(tag string, out io.WriteCloser, in io.ReadCloser, promCounter pr
...
@@ -190,16 +190,17 @@ func copyStream(tag string, out io.WriteCloser, in io.ReadCloser, promCounter pr
if
cntr
!=
nil
{
if
cntr
!=
nil
{
atomic
.
AddUint64
(
cntr
,
uint64
(
n
))
atomic
.
AddUint64
(
cntr
,
uint64
(
n
))
}
}
if
err
!=
nil
&&
!
is
Close
Error
(
err
)
{
if
err
!=
nil
&&
is
Interesting
Error
(
err
)
{
log
.
Printf
(
"http: proxy error (%s): %v"
,
tag
,
err
)
log
.
Printf
(
"
error:
http: proxy error (%s): %v"
,
tag
,
err
)
}
}
}
}
// This is a bad implementation (see https://github.com/golang/go/issues/4373
// This is a bad implementation (see https://github.com/golang/go/issues/4373
// for some notes on why it is a layering violation), and we could replace it
// for some notes on why it is a layering violation), and we could replace it
// with an atomic 'closing' flag.
// with an atomic 'closing' flag.
func
isCloseError
(
err
error
)
bool
{
func
isInterestingError
(
err
error
)
bool
{
return
strings
.
Contains
(
err
.
Error
(),
"use of closed network connection"
)
s
:=
err
.
Error
()
return
!
(
strings
.
Contains
(
s
,
"use of closed network connection"
)
||
strings
.
Contains
(
s
,
"connection reset by peer"
))
}
}
// Simple two-way TCP proxy that copies data in both directions and
// Simple two-way TCP proxy that copies data in both directions and
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment