fix: #35 peer Registration Race when client connects to the signal server

This commit is contained in:
braginini
2021-06-17 11:12:35 +02:00
parent 9308a51800
commit db673ed34f
4 changed files with 20 additions and 2 deletions

View File

@@ -109,8 +109,6 @@ func (c *Client) connect(key string, msgHandler func(msg *proto.Message) error)
// add key fingerprint to the request header to be identified on the server side
md := metadata.New(map[string]string{proto.HeaderId: key})
ctx := metadata.NewOutgoingContext(c.ctx, md)
//ctx, cancel := context.WithCancel(ctx)
//defer cancel()
stream, err := c.realClient.ConnectStream(ctx)
@@ -118,6 +116,15 @@ func (c *Client) connect(key string, msgHandler func(msg *proto.Message) error)
if err != nil {
return err
}
// blocks
header, err := c.stream.Header()
if err != nil {
return err
}
registered := header.Get(proto.HeaderRegistered)
if len(registered) == 0 {
return fmt.Errorf("didn't receive a registration header from the Signal server whille connecting to the streams")
}
//connection established we are good to use the stream
c.connWg.Done()