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
39abd92c
Unverified
Commit
39abd92c
authored
Jun 08, 2020
by
ucwong
Committed by
GitHub
Jun 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethstats: use timer instead of time.sleep (#20924)
parent
45b75351
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
62 deletions
+71
-62
ethstats.go
ethstats/ethstats.go
+71
-62
No files found.
ethstats/ethstats.go
View file @
39abd92c
...
...
@@ -203,8 +203,15 @@ func (s *Service) loop() {
if
!
strings
.
Contains
(
path
,
"://"
)
{
urls
=
[]
string
{
"wss://"
+
path
,
"ws://"
+
path
}
}
errTimer
:=
time
.
NewTimer
(
0
)
defer
errTimer
.
Stop
()
// Loop reporting until termination
for
{
select
{
case
<-
quitCh
:
return
case
<-
errTimer
.
C
:
// Establish a websocket connection to the server on any supported URL
var
(
conn
*
websocket
.
Conn
...
...
@@ -221,14 +228,14 @@ func (s *Service) loop() {
}
if
err
!=
nil
{
log
.
Warn
(
"Stats server unreachable"
,
"err"
,
err
)
time
.
Sleep
(
10
*
time
.
Second
)
errTimer
.
Reset
(
10
*
time
.
Second
)
continue
}
// Authenticate the client with the server
if
err
=
s
.
login
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Stats login failed"
,
"err"
,
err
)
conn
.
Close
()
time
.
Sleep
(
10
*
time
.
Second
)
errTimer
.
Reset
(
10
*
time
.
Second
)
continue
}
go
s
.
readLoop
(
conn
)
...
...
@@ -237,6 +244,7 @@ func (s *Service) loop() {
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Initial stats report failed"
,
"err"
,
err
)
conn
.
Close
()
errTimer
.
Reset
(
0
)
continue
}
// Keep sending status updates until the connection breaks
...
...
@@ -275,6 +283,7 @@ func (s *Service) loop() {
// Make sure the connection is closed
conn
.
Close
()
}
}
}
// readLoop loops as long as the connection is alive and retrieves data packets
...
...
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