fix 如果报错,就会拒绝服务的问题

This commit is contained in:
wangjian 2023-04-05 11:17:38 +08:00
parent d10a80765e
commit 6ce4bf7726
1 changed files with 9 additions and 5 deletions

View File

@ -127,21 +127,22 @@ func (s *Server) createNewClientConnection(ctx context.Context, listener Listene
go func(ctx context.Context, qConn quic.Connection) {
for {
err := s.handle(ctx, qConn, connect, connId)
err := s.handle(ctx, qConn, connId)
if err != nil {
continue
break
}
}
}(sctx, connect)
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)
stream, err := qConn.AcceptStream(ctx)
if err != nil {
name := "--"
if conn := s.connector.Get(connId); conn != nil {
conn := s.connector.Get(connId)
if conn != nil {
_ = conn.Close()
// connector
s.connector.Remove(connId)
@ -150,6 +151,9 @@ func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Co
_ = route.Remove(connId)
}
name = conn.Name()
} else {
_ = s.Close()
}
log.Printf("%s [%s](%s) close the connection: %v", ServerLogPrefix, name, connId, 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)
// process frames on stream
// c := newContext(connId, stream)
c := newContext(conn, stream)
c := newContext(qConn, stream)
defer c.Clean()
s.handleConnection(c)
log.Infof("%s4/ [stream:%d] handleConnection DONE", ServerLogPrefix, stream.StreamID())