return a net.Error when opening streams

net.Error.Temporary() will be true if no stream can be opened when the
peer's stream limit is reached.
This commit is contained in:
Marten Seemann 2019-01-06 17:18:43 +07:00
parent 8ac77be934
commit a2e48e204b
7 changed files with 85 additions and 37 deletions

View file

@ -47,7 +47,11 @@ func (m *outgoingItemsMap) OpenStream() (item, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
return m.openStreamImpl()
str, err := m.openStreamImpl()
if err != nil {
return nil, streamOpenErr{err}
}
return str, nil
}
func (m *outgoingItemsMap) OpenStreamSync() (item, error) {
@ -57,10 +61,10 @@ func (m *outgoingItemsMap) OpenStreamSync() (item, error) {
for {
str, err := m.openStreamImpl()
if err == nil {
return str, err
return str, nil
}
if err != nil && err != qerr.TooManyOpenStreams {
return nil, err
if err != nil && err != errTooManyOpenStreams {
return nil, streamOpenErr{err}
}
m.cond.Wait()
}
@ -85,7 +89,7 @@ func (m *outgoingItemsMap) openStreamImpl() (item, error) {
}
m.blockedSent = true
}
return nil, qerr.TooManyOpenStreams
return nil, errTooManyOpenStreams
}
s := m.newStream(m.nextStream)
m.streams[m.nextStream] = s