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
1018bf6a
Commit
1018bf6a
authored
Mar 24, 2017
by
Péter Szilágyi
Committed by
Felix Lange
Mar 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: honour pending requests before tearing conn down (#3814)
parent
37e25258
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
14 deletions
+28
-14
server.go
rpc/server.go
+28
-14
No files found.
rpc/server.go
View file @
1018bf6a
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"reflect"
"runtime"
"sync"
"sync/atomic"
"github.com/ethereum/go-ethereum/log"
...
...
@@ -143,6 +144,8 @@ func hasOption(option CodecOption, options []CodecOption) bool {
// requests until the codec returns an error when reading a request (in most cases
// an EOF). It executes requests in parallel when singleShot is false.
func
(
s
*
Server
)
serveRequest
(
codec
ServerCodec
,
singleShot
bool
,
options
CodecOption
)
error
{
var
pend
sync
.
WaitGroup
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
const
size
=
64
<<
10
...
...
@@ -150,7 +153,6 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
buf
=
buf
[
:
runtime
.
Stack
(
buf
,
false
)]
log
.
Error
(
fmt
.
Sprint
(
string
(
buf
)))
}
s
.
codecsMu
.
Lock
()
s
.
codecs
.
Remove
(
codec
)
s
.
codecsMu
.
Unlock
()
...
...
@@ -179,8 +181,13 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
for
atomic
.
LoadInt32
(
&
s
.
run
)
==
1
{
reqs
,
batch
,
err
:=
s
.
readRequest
(
codec
)
if
err
!=
nil
{
log
.
Debug
(
fmt
.
Sprintf
(
"read error %v
\n
"
,
err
))
codec
.
Write
(
codec
.
CreateErrorResponse
(
nil
,
err
))
// If a parsing error occurred, send an error
if
err
.
Error
()
!=
"EOF"
{
log
.
Debug
(
fmt
.
Sprintf
(
"read error %v
\n
"
,
err
))
codec
.
Write
(
codec
.
CreateErrorResponse
(
nil
,
err
))
}
// Error or end of stream, wait for requests and tear down
pend
.
Wait
()
return
nil
}
...
...
@@ -199,20 +206,27 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
}
return
nil
}
if
singleShot
&&
batch
{
s
.
execBatch
(
ctx
,
codec
,
reqs
)
return
nil
}
else
if
singleShot
&&
!
batch
{
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
// If a single shot request is executing, run and return immediately
if
singleShot
{
if
batch
{
s
.
execBatch
(
ctx
,
codec
,
reqs
)
}
else
{
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
}
return
nil
}
else
if
!
singleShot
&&
batch
{
go
s
.
execBatch
(
ctx
,
codec
,
reqs
)
}
else
{
go
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
}
}
// For multi-shot connections, start a goroutine to serve and loop back
pend
.
Add
(
1
)
go
func
(
reqs
[]
*
serverRequest
,
batch
bool
)
{
defer
pend
.
Done
()
if
batch
{
s
.
execBatch
(
ctx
,
codec
,
reqs
)
}
else
{
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
}
}(
reqs
,
batch
)
}
return
nil
}
...
...
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