You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the listen function, the for loop checks for a ctx closed. If it is, it exits the function.
It needs to call the wg.Done.
If the Connect function is given a wrong details, the initial listen will never succeed the websocket.DialConfig.
As a result, the only way to stop this function is to cancel the context.
The problem is, the context closed does not call wg.Done prior to the return.
As a result, the Connect will be stuck at the wg.Wait and never return.
Here is code to correct the problem.
func (c *Client) listen(ctx context.Context, wg *sync.WaitGroup) {
var signalUp sync.Once
for {
// Exit if our context has been closed
if ctx.Err() != nil {
if wg != nil {
wg.Done()
}
return
}
The text was updated successfully, but these errors were encountered:
In the listen function, the for loop checks for a ctx closed. If it is, it exits the function.
It needs to call the wg.Done.
If the Connect function is given a wrong details, the initial listen will never succeed the websocket.DialConfig.
As a result, the only way to stop this function is to cancel the context.
The problem is, the context closed does not call wg.Done prior to the return.
As a result, the Connect will be stuck at the wg.Wait and never return.
Here is code to correct the problem.
func (c *Client) listen(ctx context.Context, wg *sync.WaitGroup) {
var signalUp sync.Once
The text was updated successfully, but these errors were encountered: