fix race when dialing a new connection

When a connection error occurs, Dial can only return the error if the
session is closed with that error. Therefore, the session must be
created before client.listen() is called.
This commit is contained in:
Marten Seemann
2017-12-21 13:25:49 +07:00
parent edb5fd751c
commit 2a0b71c66b

View File

@@ -115,7 +115,6 @@ func DialNonFWSecure(
}
utils.Infof("Starting new connection to %s (%s -> %s), connectionID %x, version %s", hostname, c.conn.LocalAddr().String(), c.conn.RemoteAddr().String(), c.connectionID, c.version)
go c.listen()
if err := c.dial(); err != nil {
return nil, err
@@ -199,6 +198,7 @@ func (c *client) dialGQUIC() error {
if err := c.createNewGQUICSession(); err != nil {
return err
}
go c.listen()
return c.establishSecureConnection()
}
@@ -224,6 +224,7 @@ func (c *client) dialTLS() error {
if err := c.createNewTLSSession(eh.GetPeerParams(), c.version); err != nil {
return err
}
go c.listen()
if err := c.establishSecureConnection(); err != nil {
if err != handshake.ErrCloseSessionForRetry {
return err