Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make some optimizations for http_conn.go #1059

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions bfe_server/http_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (c *conn) serve() {
var hl *bfe_module.HandlerList
var retVal int
session := c.session
c.session.Proto = "http" // init proto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的初始值可能是错的。

合理的做法:

  • A. 暂保持未知值(在不影响其它功能的前提下,等到合适的时机设置)
  • B. 采用以下方式判断
tlsConn, isTlsConn := c.rwc.(*bfe_tls.Conn)
if !isTlsConn {
     c.session.Proto = "http"
}

c.server.connWaitGroup.Add(1)
serverStatus := c.server.serverStatus
proxyState := serverStatus.ProxyState
Expand Down Expand Up @@ -316,6 +317,7 @@ func (c *conn) serve() {
}

if tlsConn, ok := c.rwc.(*bfe_tls.Conn); ok {
c.session.Proto = "https" // update proto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里设置初始值也有可能是错的.

建议:

  1. 将line 320 移动到 line 381
  2. if 条件改为 if isTlsConn

proxyState.TlsHandshakeAll.Inc(1)
var d time.Duration
// set tls handshake timeout
Expand Down Expand Up @@ -366,7 +368,7 @@ func (c *conn) serve() {
log.Logger.Debug("conn.serve(): Use negotiated protocol %s over TLS", proto)
proxyState.ClientConnServedInc(proto, 1) // Note: counter for negotiated protocol
proxyState.ClientConnActiveInc(proto, 1)
c.session.Proto = proto
c.session.Proto = proto // update proto

// process protocol over TLS connection (spdy, http2, etc)
handler := NewProtocolHandler(c, proto)
Expand All @@ -379,12 +381,6 @@ func (c *conn) serve() {
}
}

// process requests from http/https protocol
if _, ok := c.rwc.(*bfe_tls.Conn); ok {
c.session.Proto = "https"
} else {
c.session.Proto = "http"
}
proxyState.ClientConnServedInc(c.session.Proto, 1) // Note: counter for http/https protocol
proxyState.ClientConnActiveInc(c.session.Proto, 1)

Expand Down
Loading