zelenin/go-tdlib

the library didn't try to receive updates anymore when running a while

Closed this issue · 6 comments

the library didn't try to receive updates anymore when running a while

func (instance *tdlib) addClient(client *Client) {
	instance.mu.Lock()
	defer instance.mu.Unlock()

	instance.clients[client.jsonClient.id] = client

	instance.once.Do(func() {
		go instance.receiver()
	})
}

func (instance *tdlib) receiver() {
	for {
		resp, err := instance.receive(instance.timeout)
		if err != nil {
			continue
		}

		client, err := instance.getClient(resp.ClientId)
		if err != nil {
			log.Print(err)
			continue
		}

		client.responses <- resp
	}
}

I view code .it seems work

func (instance *tdlib) receiver() {
	for {
		resp, err := instance.receive(instance.timeout)
		if err != nil {
			log.Print(err)
			continue
		}
		log.Printf("clientId:%d", resp.ClientId)

		client, err := instance.getClient(resp.ClientId)
		if err != nil {
			log.Print(err)
			continue
		}

		client.responses <- resp
	}
}
func (instance *tdlib) receive(timeout time.Duration) (*Response, error) {
	result := C.td_receive(C.double(float64(timeout) / float64(time.Second)))
	if result == nil {
		return nil, errors.New("update receiving timeout")
	}

	data := []byte(C.GoString(result))

	var resp Response

	err := json.Unmarshal(data, &resp)
	if err != nil {
		return nil, err
	}

	resp.Data = data

	return &resp, nil
}

I debug the code and that seems bad
image

this is tdlib issue, not go-tdlib

the listener.updates is fulled and blocking td_receive

the listener.updates is fulled and blocking td_receive

did you find way to fix it i am facing the same issue

@purex121 you should add event filter