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

Client stops receiving messages #139

Open
iamsaso opened this issue Aug 11, 2017 · 1 comment
Open

Client stops receiving messages #139

iamsaso opened this issue Aug 11, 2017 · 1 comment

Comments

@iamsaso
Copy link

iamsaso commented Aug 11, 2017

I am connecting to a websocket and randomly my app stops receiving messages. There is no message that anything failed or that websocket was disconnected or server went away... Did anyone experiance same problems and is there a way to check if everything is ok (like ping) and to reconnect if server goes down.

@gngeorgiev, @beatgammit, @digitallumens, @dcarbone sry for ping but I see you are all maintaining your own forks... has anyone experienced similar issues and maybe created a fix that I can test/use?

func (c *Client) Ticker(ctx context.Context) (<-chan *Symbol, error) {
	symbols := make(chan *Symbol)
	var once sync.Once

	client, err := turnpike.NewWebsocketClient(turnpike.JSON, "wss://api.poloniex.com", nil, nil)
	if err != nil {
		log.Fatal(err)
	}

	client.ReceiveTimeout = 30 * time.Second
	_, err = client.JoinRealm("realm1", nil)
	if err != nil {
		log.Fatal(err)
	}

	err = client.Subscribe("ticker", nil, turnpike.EventHandler(func(args []interface{}, kwargs map[string]interface{}) {
		symbol, err := toSymbol(args)
		if err != nil {
			log.Println("encountered an error converting an event to a Symbol:", err)
		}

		select {
		case <-ctx.Done():
			once.Do(func() {
				close(symbols)
				symbols = nil
				if err := client.Unsubscribe("ticker"); err != nil {
					log.Println("encountered error during unsubscription:", err)
				}
				log.Println("Ticker disconnected")
			})
		case symbols <- symbol:
		}
	}))
	if err != nil {
		log.Println("encountered an error subscribing to the 'ticker' topic:", errors.Wrap(err, "error subscribing to 'ticker' topic"))
		return nil, errors.WithStack(err)
	}

	return symbols, nil
}
@utdrmac
Copy link

utdrmac commented May 1, 2018

@Sasso Any update on this? Running into a similar issue and I was also wondering about 'ping' ability. I've wrapped NewWebsocketClient and JoinRealm/Subscribe inside some infinite-for-loops so that if connection drops, it will auto-retry after a sleep timeout. I'm having "trust" issues that once I connect to the wss I really am connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants