Skip to content

Commit

Permalink
pkg/core/session: Add WithReceiveTimeout SessionOpt
Browse files Browse the repository at this point in the history
Current code does not retry enough time on receive (hard-coded to 1s)
and some devices (for example Intel SSDPE2KX040T8O) operation
such as "PSID Revert" takes ~15s.

This results always in a timeout error:

"method call timed out waiting for a response"

Exposing SessionOpt to override default 100*10ms polling for receive will
allow calling code to override these defaults.
  • Loading branch information
yogev-lb committed Jul 6, 2022
1 parent 94c7e53 commit add36fb
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions pkg/core/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type Session struct {
SeqLastAcked int
SeqNextExpected int
ReadOnly bool // Ignored for Control Sessions
ReceiveRetries int
ReceiveInterval time.Duration
}

type ControlSession struct {
Expand Down Expand Up @@ -162,6 +164,13 @@ func WithMaxComPacketSize(size uint) ControlSessionOpt {
}
}

func WithReceiveTimeout(retries int, interval time.Duration) SessionOpt {
return func(s *Session) {
s.ReceiveRetries = retries
s.ReceiveInterval = interval
}
}

func WithHSN(hsn int) SessionOpt {
return func(s *Session) {
s.HSN = hsn
Expand Down Expand Up @@ -207,11 +216,13 @@ func NewControlSession(d drive.DriveIntf, d0 *Level0Discovery, opts ...ControlSe
c := NewPlainCommunication(d, hp, tp)
s := &ControlSession{
Session: Session{
d: d,
c: c,
ComID: ComIDInvalid,
TSN: 0,
HSN: 0,
d: d,
c: c,
ComID: ComIDInvalid,
TSN: 0,
HSN: 0,
ReceiveRetries: 100,
ReceiveInterval: 10 * time.Millisecond,
},
HostProperties: hp,
TPerProperties: tp,
Expand Down Expand Up @@ -321,14 +332,16 @@ func (cs *ControlSession) NewSession(spid uid.SPID, opts ...SessionOpt) (*Sessio
// then and the call to NewSession() we would be out of sync. Oh well...

s := &Session{
MethodFlags: cs.MethodFlags,
ProtocolLevel: cs.ProtocolLevel,
d: cs.d,
c: cs.c,
ControlSession: cs,
ComID: cs.ComID,
TSN: 0,
HSN: -1,
MethodFlags: cs.MethodFlags,
ProtocolLevel: cs.ProtocolLevel,
d: cs.d,
c: cs.c,
ControlSession: cs,
ComID: cs.ComID,
TSN: 0,
HSN: -1,
ReceiveRetries: 100,
ReceiveInterval: 10 * time.Millisecond,
}

for _, opt := range opts {
Expand Down Expand Up @@ -523,7 +536,8 @@ func (s *Session) ExecuteMethod(mc *method.MethodCall) (stream.List, error) {
// > response, any IF-RECV command for that ComID SHALL receive a ComPacket with a
// > Length field value of zero (no payload), an OutstandingData field value of 0x01, and a
// > MinTransfer field value of zero.
for i := 100; i >= 0; i-- {

for i := s.ReceiveRetries; i >= 0; i-- {
resp, err = s.c.Receive(s)
if err != nil {
return nil, err
Expand All @@ -534,7 +548,7 @@ func (s *Session) ExecuteMethod(mc *method.MethodCall) (stream.List, error) {
if i == 0 {
return nil, method.ErrMethodTimeout
}
time.Sleep(10 * time.Millisecond)
time.Sleep(s.ReceiveInterval)
}

reply, err := stream.Decode(resp)
Expand Down

0 comments on commit add36fb

Please sign in to comment.