revid: ignoring rtmp.ErrInvalidFlvTag error and checking that rtmp conn is not closed before we try to close it

This commit is contained in:
Saxon 2019-03-03 18:24:54 +10:30
parent 9c59c5b9d3
commit 8606320731
4 changed files with 11 additions and 5 deletions

View File

@ -298,6 +298,9 @@ func (s *rtmpSender) load(c *ring.Chunk) error {
func (s *rtmpSender) send() error {
_, err := s.chunk.WriteTo(s.conn)
if err == rtmp.ErrInvalidFlvTag {
return nil
}
return err
}
@ -307,7 +310,7 @@ func (s *rtmpSender) release() {
}
func (s *rtmpSender) restart() error {
s.conn.Close()
s.close()
var err error
for n := 0; n < s.retries; n++ {
s.conn, err = rtmp.Dial(s.url, s.timeout, s.log)
@ -323,7 +326,10 @@ func (s *rtmpSender) restart() error {
}
func (s *rtmpSender) close() error {
return s.conn.Close()
if s.conn != nil {
return s.conn.Close()
}
return nil
}
// udpSender implements loadSender for a native udp destination.

View File

@ -155,7 +155,7 @@ func (c *Conn) Write(data []byte) (int, error) {
return 0, errNotConnected
}
if len(data) < flvTagheaderSize {
return 0, errInvalidFlvTag
return 0, ErrInvalidFlvTag
}
if data[0] == packetTypeInfo || (data[0] == 'F' && data[1] == 'L' && data[2] == 'V') {
return 0, errUnimplemented

View File

@ -158,7 +158,7 @@ var (
errNotWritable = errors.New("rtmp: connection not writable")
errInvalidHeader = errors.New("rtmp: invalid header")
errInvalidBody = errors.New("rtmp: invalid body")
errInvalidFlvTag = errors.New("rtmp: invalid FLV tag")
ErrInvalidFlvTag = errors.New("rtmp: invalid FLV tag")
errUnimplemented = errors.New("rtmp: unimplemented feature")
)

View File

@ -216,7 +216,7 @@ type rtmpSender struct {
func (rs *rtmpSender) Write(p []byte) (int, error) {
n, err := rs.conn.Write(p)
if err != errInvalidFlvTag && err != nil {
if err != ErrInvalidFlvTag && err != nil {
return 0, err
}
return n, nil