-
Notifications
You must be signed in to change notification settings - Fork 13
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
martian: move TLS handshake from forwarder.Listener #941
Conversation
The question is what do we do with the tls handshake metric? |
Listener is not the right place to do the handshake. It may block main accept loop.
I rebased and added a test.
That approach resigns from having a tls error metrics in forwarder. We don't have any metrics directly in martian and I see no point in adding it only for that. |
internal/martian/proxy.go
Outdated
pc := newProxyConn(p, conn) | ||
pc, err := newProxyConn(p, conn) | ||
if err != nil { | ||
log.Errorf(context.TODO(), "failed to create proxy connection: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe initialize would be better?
internal/martian/proxy_conn.go
Outdated
ctx := context.Background() | ||
if p.TLSHandshakeTimeout > 0 { | ||
var cancel context.CancelFunc | ||
ctx, cancel = context.WithTimeout(context.Background(), p.TLSHandshakeTimeout) | ||
defer cancel() | ||
} | ||
if err := tconn.HandshakeContext(ctx); err != nil { | ||
return nil, fmt.Errorf("failed to do TLS handshake: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be extracted to method so that newProxyConn
does not return error.
This would give us the opportunity to provide better errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A separate method to do the handshake has been added.
internal/martian/proxy_conn.go
Outdated
if tconn, ok := conn.(*tls.Conn); ok { | ||
v.secure = true | ||
v.cs = tconn.ConnectionState() | ||
func (p *proxyConn) tlsHandshake() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call that maybeHandshakeTLS
internal/martian/proxy_conn.go
Outdated
v.secure = true | ||
v.cs = tconn.ConnectionState() | ||
func (p *proxyConn) tlsHandshake() error { | ||
if tconn, ok := p.conn.(*tls.Conn); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return early.
Martian Proxy will explicitly do the handshake if accepted connection is tls.Conn.
LGTM |
Listener is not the right place to do the handshake. It may block main accept loop.
Martian Proxy will explicitly do the handshake if accepted connection is tls.Conn.
Consequences:
Fixes #917