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

stopPolling() doesn't cancel the polling connection #455

Open
peoro opened this issue Nov 7, 2017 · 7 comments
Open

stopPolling() doesn't cancel the polling connection #455

peoro opened this issue Nov 7, 2017 · 7 comments

Comments

@peoro
Copy link

peoro commented Nov 7, 2017

Bug Report

I have read:

I am using the latest version of the library.

Expected Behavior

After calling stopPolling no listener should be left waiting for polling-related events: if no other event handlers are active, Node's event loop should terminate.

Actual Behavior

A TLSSocket object starts listening on a socket when polling starts. stopPolling doesn't stop it.

This is because HTTPS requests to the Telegram server use the forever agent (src/telegram.js:230), and the agent is not cancelled by stopPolling (which calls this._polling.stop(): src/telegramPolling.js:57)

Steps to reproduce the Behavior

Run the following piece of code:

const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot(TOKEN, {polling:true});
bot.stopPolling();

This program never terminates as the polling request is still active.

@GochoMugo
Copy link
Collaborator

I can not seem to reproduce this bug. Which Node.js version are you using?

@peoro
Copy link
Author

peoro commented Nov 18, 2017

I'm using node 8.8.1 on some machines and 9.2.0 on others.

I just tried again to run the snippet I provided and noticed something weird: the behaviour changes depending on the bot.
I just created a brand new bot to test this, and the script above constantly takes 10 seconds to terminate (between 10.2 and 10.5 real time seconds, every single time), both on node 8.8.1 and 9.2.0. Then I started a conversation with the bot (i.e. I sent it /start), and now the snippet is terminating instantly.

Could you try reproducing this bug using the token of a newly created bot?

I cannot use the bot I was using when I created this issue (since a program is already polling on it and I cannot stop it now), but the snippet was definitely taking longer than 10 seconds to terminate with that bot.

@arenddeboer
Copy link

I thought I was hitting this bug too, but giving it a better look it may help to provide cancel: true as object property. eg:

bot.stopPolling({
        cancel: true,
        reason: 'Lost leader status'
    })

Just for anyone running into this.

@PtruckStar
Copy link

@arenddeboer did this but still getting an error when restarting the bot

error: [polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}

@milad2golnia
Copy link

I have this problem yet even when calling bot.stopPolling({ cancel: true });.

@FirstAlertDunc
Copy link

FirstAlertDunc commented Oct 20, 2023

I have been experiencing this issue too - I found that by setting the bot._polling._abort flag to true just after calling bot.stopPolling(), it stopped the execution as expected.

Looks like this flag is only being set if the options.cancel property is not set - thus it cancels the promise, but never stops execution.

Selection_564

Perhaps the flag could be set just after (or before) the timer is cleared?

@FirstAlertDunc
Copy link

Ah also why is there a "reason" being provided to the Bluebird's Promise.cancel() method when it doesn't accept any arguments?

Selection_565

Is this for future feature provision or something? Not against doing it - just noticed it doesn't seem to go anywhere?

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

No branches or pull requests

6 participants