Skip to content

Commit 3868359

Browse files
authored
refactoring(p2p): remove timeout from handling the request range (#11)
We do not need a timeout in handling the range request on the server side, as we have implemented an extra check that ensures that this range has a height less than store.Head
1 parent 5f7bed6 commit 3868359

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

p2p/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ type ServerParameters struct {
3232
// DefaultServerParameters returns the default params to configure the store.
3333
func DefaultServerParameters() ServerParameters {
3434
return ServerParameters{
35-
WriteDeadline: time.Second * 5,
35+
WriteDeadline: time.Second * 8,
3636
ReadDeadline: time.Minute,
37-
RangeRequestTimeout: time.Second * 5,
37+
RangeRequestTimeout: time.Second * 10,
3838
}
3939
}
4040

p2p/server.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ func (serv *ExchangeServer[H]) requestHandler(stream network.Stream) {
123123
if code != p2p_pb.StatusCode_OK {
124124
headers = make([]H, 1)
125125
}
126+
127+
if err := stream.SetWriteDeadline(time.Now().Add(serv.Params.WriteDeadline)); err != nil {
128+
log.Debugf("error setting deadline: %s", err)
129+
}
130+
126131
// write all headers to stream
127132
for _, h := range headers {
128-
if err := stream.SetWriteDeadline(time.Now().Add(serv.Params.ReadDeadline)); err != nil {
129-
log.Debugf("error setting deadline: %s", err)
130-
}
131133
var bin []byte
132134
// if header is not nil, then marshal it to []byte.
133135
// if header is nil, then error was received,so we will set empty []byte to proto.
@@ -186,10 +188,7 @@ func (serv *ExchangeServer[H]) handleRequest(from, to uint64) ([]H, error) {
186188
return serv.handleHeadRequest()
187189
}
188190

189-
ctx, cancel := context.WithTimeout(serv.ctx, serv.Params.RangeRequestTimeout)
190-
defer cancel()
191-
192-
ctx, span := tracer.Start(ctx, "request-range", trace.WithAttributes(
191+
ctx, span := tracer.Start(serv.ctx, "request-range", trace.WithAttributes(
193192
attribute.Int64("from", int64(from)),
194193
attribute.Int64("to", int64(to))))
195194
defer span.End()

0 commit comments

Comments
 (0)