don't wrap close errors in the streams map

A close error might for example be a timeout error. We want to preserve
the fact that it satisfies the net.Error interface and that Timeout() ==
true.
This commit is contained in:
Marten Seemann 2019-03-02 17:58:18 +09:00
parent 42ea34048a
commit c03a8aaa97
4 changed files with 23 additions and 18 deletions

View file

@ -49,6 +49,10 @@ func (m *outgoingBidiStreamsMap) OpenStream() (streamI, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
if m.closeErr != nil {
return nil, m.closeErr
}
str, err := m.openStreamImpl()
if err != nil {
return nil, streamOpenErr{err}
@ -61,6 +65,9 @@ func (m *outgoingBidiStreamsMap) OpenStreamSync() (streamI, error) {
defer m.mutex.Unlock()
for {
if m.closeErr != nil {
return nil, m.closeErr
}
str, err := m.openStreamImpl()
if err == nil {
return str, nil
@ -73,9 +80,6 @@ func (m *outgoingBidiStreamsMap) OpenStreamSync() (streamI, error) {
}
func (m *outgoingBidiStreamsMap) openStreamImpl() (streamI, error) {
if m.closeErr != nil {
return nil, m.closeErr
}
if !m.maxStreamSet || m.nextStream > m.maxStream {
if !m.blockedSent {
if m.maxStreamSet {

View file

@ -47,6 +47,10 @@ func (m *outgoingItemsMap) OpenStream() (item, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
if m.closeErr != nil {
return nil, m.closeErr
}
str, err := m.openStreamImpl()
if err != nil {
return nil, streamOpenErr{err}
@ -59,6 +63,9 @@ func (m *outgoingItemsMap) OpenStreamSync() (item, error) {
defer m.mutex.Unlock()
for {
if m.closeErr != nil {
return nil, m.closeErr
}
str, err := m.openStreamImpl()
if err == nil {
return str, nil
@ -71,9 +78,6 @@ func (m *outgoingItemsMap) OpenStreamSync() (item, error) {
}
func (m *outgoingItemsMap) openStreamImpl() (item, error) {
if m.closeErr != nil {
return nil, m.closeErr
}
if !m.maxStreamSet || m.nextStream > m.maxStream {
if !m.blockedSent {
if m.maxStreamSet {

View file

@ -2,7 +2,6 @@ package quic
import (
"errors"
"net"
"github.com/golang/mock/gomock"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -47,12 +46,7 @@ var _ = Describe("Streams Map (outgoing)", func() {
testErr := errors.New("close")
m.CloseWithError(testErr)
_, err := m.OpenStream()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(testErr.Error()))
nerr, ok := err.(net.Error)
Expect(ok).To(BeTrue())
Expect(nerr.Timeout()).To(BeFalse())
Expect(nerr.Temporary()).To(BeFalse())
Expect(err).To(MatchError(testErr))
})
It("gets streams", func() {
@ -155,8 +149,7 @@ var _ = Describe("Streams Map (outgoing)", func() {
go func() {
defer GinkgoRecover()
_, err := m.OpenStreamSync()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(testErr.Error()))
Expect(err).To(MatchError(testErr))
close(done)
}()

View file

@ -49,6 +49,10 @@ func (m *outgoingUniStreamsMap) OpenStream() (sendStreamI, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
if m.closeErr != nil {
return nil, m.closeErr
}
str, err := m.openStreamImpl()
if err != nil {
return nil, streamOpenErr{err}
@ -61,6 +65,9 @@ func (m *outgoingUniStreamsMap) OpenStreamSync() (sendStreamI, error) {
defer m.mutex.Unlock()
for {
if m.closeErr != nil {
return nil, m.closeErr
}
str, err := m.openStreamImpl()
if err == nil {
return str, nil
@ -73,9 +80,6 @@ func (m *outgoingUniStreamsMap) OpenStreamSync() (sendStreamI, error) {
}
func (m *outgoingUniStreamsMap) openStreamImpl() (sendStreamI, error) {
if m.closeErr != nil {
return nil, m.closeErr
}
if !m.maxStreamSet || m.nextStream > m.maxStream {
if !m.blockedSent {
if m.maxStreamSet {