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
9f45d6ef
Unverified
Commit
9f45d6ef
authored
4 years ago
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethstats: split read and write lock, otherwise they'll lock up
parent
cbbc54c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
ethstats.go
ethstats/ethstats.go
+18
-14
No files found.
ethstats/ethstats.go
View file @
9f45d6ef
...
...
@@ -99,19 +99,20 @@ type Service struct {
// connWrapper is a wrapper to prevent concurrent-write or concurrent-read on the
// websocket.
// From Gorilla websocket docs:
// Connections support one concurrent reader and one concurrent writer.
// Applications are responsible for ensuring that no more than one goroutine calls the write methods
// - NextWriter, SetWriteDeadline, WriteMessage, WriteJSON, EnableWriteCompression, SetCompressionLevel
// concurrently and that no more than one goroutine calls the read methods
// - NextReader, SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler
// concurrently.
// The Close and WriteControl methods can be called concurrently with all other methods.
//
// The connWrapper uses a single mutex for both reading and writing.
// From Gorilla websocket docs:
// Connections support one concurrent reader and one concurrent writer.
// Applications are responsible for ensuring that no more than one goroutine calls the write methods
// - NextWriter, SetWriteDeadline, WriteMessage, WriteJSON, EnableWriteCompression, SetCompressionLevel
// concurrently and that no more than one goroutine calls the read methods
// - NextReader, SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler
// concurrently.
// The Close and WriteControl methods can be called concurrently with all other methods.
type
connWrapper
struct
{
conn
*
websocket
.
Conn
mu
sync
.
Mutex
rlock
sync
.
Mutex
wlock
sync
.
Mutex
}
func
newConnectionWrapper
(
conn
*
websocket
.
Conn
)
*
connWrapper
{
...
...
@@ -120,15 +121,17 @@ func newConnectionWrapper(conn *websocket.Conn) *connWrapper {
// WriteJSON wraps corresponding method on the websocket but is safe for concurrent calling
func
(
w
*
connWrapper
)
WriteJSON
(
v
interface
{})
error
{
w
.
mu
.
Lock
()
defer
w
.
mu
.
Unlock
()
w
.
wlock
.
Lock
()
defer
w
.
wlock
.
Unlock
()
return
w
.
conn
.
WriteJSON
(
v
)
}
// ReadJSON wraps corresponding method on the websocket but is safe for concurrent calling
func
(
w
*
connWrapper
)
ReadJSON
(
v
interface
{})
error
{
w
.
mu
.
Lock
()
defer
w
.
mu
.
Unlock
()
w
.
rlock
.
Lock
()
defer
w
.
rlock
.
Unlock
()
return
w
.
conn
.
ReadJSON
(
v
)
}
...
...
@@ -275,6 +278,7 @@ func (s *Service) loop() {
continue
}
go
s
.
readLoop
(
conn
)
// Send the initial stats so our node looks decent from the get go
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Initial stats report failed"
,
"err"
,
err
)
...
...
This diff is collapsed.
Click to expand 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