fix 如果报错,就会拒绝服务的问题
This commit is contained in:
parent
d10a80765e
commit
6ce4bf7726
14
server.go
14
server.go
|
@ -127,21 +127,22 @@ func (s *Server) createNewClientConnection(ctx context.Context, listener Listene
|
||||||
|
|
||||||
go func(ctx context.Context, qConn quic.Connection) {
|
go func(ctx context.Context, qConn quic.Connection) {
|
||||||
for {
|
for {
|
||||||
err := s.handle(ctx, qConn, connect, connId)
|
err := s.handle(ctx, qConn, connId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(sctx, connect)
|
}(sctx, connect)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Connection, connId string) error {
|
func (s *Server) handle(ctx context.Context, qConn quic.Connection, connId string) error {
|
||||||
log.Infof("%s2/ waiting for new stream", ServerLogPrefix)
|
log.Infof("%s2/ waiting for new stream", ServerLogPrefix)
|
||||||
stream, err := qConn.AcceptStream(ctx)
|
stream, err := qConn.AcceptStream(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
name := "--"
|
name := "--"
|
||||||
if conn := s.connector.Get(connId); conn != nil {
|
conn := s.connector.Get(connId)
|
||||||
|
if conn != nil {
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
// connector
|
// connector
|
||||||
s.connector.Remove(connId)
|
s.connector.Remove(connId)
|
||||||
|
@ -150,6 +151,9 @@ func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Co
|
||||||
_ = route.Remove(connId)
|
_ = route.Remove(connId)
|
||||||
}
|
}
|
||||||
name = conn.Name()
|
name = conn.Name()
|
||||||
|
} else {
|
||||||
|
_ = s.Close()
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Printf("%s [%s](%s) close the connection: %v", ServerLogPrefix, name, connId, err)
|
log.Printf("%s [%s](%s) close the connection: %v", ServerLogPrefix, name, connId, err)
|
||||||
return err
|
return err
|
||||||
|
@ -161,7 +165,7 @@ func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Co
|
||||||
log.Infof("%s3/ [stream:%d] created, connId=%s", ServerLogPrefix, stream.StreamID(), connId)
|
log.Infof("%s3/ [stream:%d] created, connId=%s", ServerLogPrefix, stream.StreamID(), connId)
|
||||||
// process frames on stream
|
// process frames on stream
|
||||||
// c := newContext(connId, stream)
|
// c := newContext(connId, stream)
|
||||||
c := newContext(conn, stream)
|
c := newContext(qConn, stream)
|
||||||
defer c.Clean()
|
defer c.Clean()
|
||||||
s.handleConnection(c)
|
s.handleConnection(c)
|
||||||
log.Infof("%s4/ [stream:%d] handleConnection DONE", ServerLogPrefix, stream.StreamID())
|
log.Infof("%s4/ [stream:%d] handleConnection DONE", ServerLogPrefix, stream.StreamID())
|
||||||
|
|
Loading…
Reference in New Issue