Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a188a1e1
Unverified
Commit
a188a1e1
authored
May 13, 2020
by
Hao Duan
Committed by
GitHub
May 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethstats: stop report ticker in each loop cycle #21070 (#21071)
Co-authored-by:
Hao Duan
<
duan.hao@hyperchain.cn
>
parent
d02301f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
ethstats.go
ethstats/ethstats.go
+13
-10
No files found.
ethstats/ethstats.go
View file @
a188a1e1
...
@@ -154,7 +154,7 @@ func (s *Service) loop() {
...
@@ -154,7 +154,7 @@ func (s *Service) loop() {
txSub
:=
txpool
.
SubscribeNewTxsEvent
(
txEventCh
)
txSub
:=
txpool
.
SubscribeNewTxsEvent
(
txEventCh
)
defer
txSub
.
Unsubscribe
()
defer
txSub
.
Unsubscribe
()
// Start a goroutine that exhausts the subsciptions to avoid events piling up
// Start a goroutine that exhausts the subsc
r
iptions to avoid events piling up
var
(
var
(
quitCh
=
make
(
chan
struct
{})
quitCh
=
make
(
chan
struct
{})
headCh
=
make
(
chan
*
types
.
Block
,
1
)
headCh
=
make
(
chan
*
types
.
Block
,
1
)
...
@@ -194,16 +194,17 @@ func (s *Service) loop() {
...
@@ -194,16 +194,17 @@ func (s *Service) loop() {
}
}
close
(
quitCh
)
close
(
quitCh
)
}()
}()
// Resolve the URL, defaulting to TLS, but falling back to none too
path
:=
fmt
.
Sprintf
(
"%s/api"
,
s
.
host
)
urls
:=
[]
string
{
path
}
// url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779)
if
!
strings
.
Contains
(
path
,
"://"
)
{
urls
=
[]
string
{
"wss://"
+
path
,
"ws://"
+
path
}
}
// Loop reporting until termination
// Loop reporting until termination
for
{
for
{
// Resolve the URL, defaulting to TLS, but falling back to none too
path
:=
fmt
.
Sprintf
(
"%s/api"
,
s
.
host
)
urls
:=
[]
string
{
path
}
// url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779)
if
!
strings
.
Contains
(
path
,
"://"
)
{
urls
=
[]
string
{
"wss://"
+
path
,
"ws://"
+
path
}
}
// Establish a websocket connection to the server on any supported URL
// Establish a websocket connection to the server on any supported URL
var
(
var
(
conn
*
websocket
.
Conn
conn
*
websocket
.
Conn
...
@@ -240,11 +241,12 @@ func (s *Service) loop() {
...
@@ -240,11 +241,12 @@ func (s *Service) loop() {
}
}
// Keep sending status updates until the connection breaks
// Keep sending status updates until the connection breaks
fullReport
:=
time
.
NewTicker
(
15
*
time
.
Second
)
fullReport
:=
time
.
NewTicker
(
15
*
time
.
Second
)
defer
fullReport
.
Stop
()
for
err
==
nil
{
for
err
==
nil
{
select
{
select
{
case
<-
quitCh
:
case
<-
quitCh
:
fullReport
.
Stop
()
// Make sure the connection is closed
conn
.
Close
()
conn
.
Close
()
return
return
...
@@ -269,6 +271,7 @@ func (s *Service) loop() {
...
@@ -269,6 +271,7 @@ func (s *Service) loop() {
}
}
}
}
}
}
fullReport
.
Stop
()
// Make sure the connection is closed
// Make sure the connection is closed
conn
.
Close
()
conn
.
Close
()
}
}
...
...
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