telegram-s / telegram-bot

32 stars 23 forks source link

Loading fresh DC list timeout #2

Closed Thus0 closed 10 years ago

Thus0 commented 10 years ago

Do we need to configure something for the telegram-bot or it should work out-of-the-box ?

I've run the bot on the production or test servers and I get a timeout when it tries to do a rpc call in the login() method

...
:app:run
Use test DC? (write test for test servers): Using production servers
Loading fresh DC list...Exception in thread "main" org.telegram.api.engine.TimeoutException
        at org.telegram.api.engine.TelegramApi.doRpcCall(TelegramApi.java:327)
        at org.telegram.api.engine.TelegramApi.doRpcCallNonAuth(TelegramApi.java:391)
        at org.telegram.api.engine.TelegramApi.doRpcCallNonAuth(TelegramApi.java:383)
        at org.telegram.bot.Application.login(Application.java:382)
        at org.telegram.bot.Application.main(Application.java:40)
floens commented 10 years ago

Check out this piece of code taken from the Telegram app: https://github.com/ex3ndr/telegram/blob/499eb24891371f57a801a08cd2385ab30299113a/app/src/main/java/org/telegram/android/core/background/sync/BackgroundSync.java#L139

try {
    TLConfig config = application.getApi().doRpcCallNonAuth(new TLRequestHelpGetConfig());
    application.getApiStorage().updateSettings(config);
    application.getTechKernel().getSystemConfig().onConfig(config);
    application.getApi().resetConnectionInfo();
    synced = true;
} catch (TimeoutException e) {
    int[] knownDcs = application.getApiStorage().getKnownDc();
    for (int i = 0; i < knownDcs.length; i++) {
        try {
            TLConfig config = application.getApi().doRpcCallNonAuth(new TLRequestHelpGetConfig(), knownDcs[i]);
            application.getApiStorage().updateSettings(config);
            application.getTechKernel().getSystemConfig().onConfig(config);
            application.getApi().resetConnectionInfo();
            synced = true;
            break;
        } catch (TimeoutException e1) {

        }
    }
}

Apparently you need to catch the timeout exception and provide your own datacenter addresses, or something like that.

Thus0 commented 10 years ago

I've tested the bot on linux/gentoo (java 1.6.0_45) and perhaps it's a duplicate bug of this one : https://github.com/ex3ndr/telegram-api/issues/9#issuecomment-37809473 and it's related to the jvm ?

Thus0 commented 10 years ago

It works on Windows with jvm 1.6 (no timeout) with production server :)

floens commented 10 years ago

Check out the solution everyone who came here from Google: https://github.com/ex3ndr/telegram-api/issues/9#issuecomment-38175765

cancerian0684 commented 9 years ago

It started working for me after I updated Server IP Address in the MemoryStateAPI class, as shown below -

 public void start(boolean isTest) {
        connections = new HashMap<>();
        connections.put(1, new ConnectionInfo[]{
                new ConnectionInfo(1, 0, isTest ? "149.154.175.10" : "149.154.175.50", 443)
        });
    }
LukeLR commented 9 years ago

Yes, it's just the Datacenter IPs that are outdated. I just started using this project for learning purposes, and I quickly figured that out. Just needed to follow the stack trace ;) I forked the repo, updated the IPs and submitted a pull request (#12) ;) But until this is done, you can use my fork of the repo https://github.com/LukeLR/telegram-bot which is exactly the same code with the updated IPs ;) This should fix your issue