rubenlagus / TelegramApi

Java library to create Telegram Clients
MIT License
295 stars 109 forks source link

404 error during MTProto working & leaking problem #62

Open c0ldd opened 6 years ago

c0ldd commented 6 years ago

Recently start receiving 404 error code from telegram while MTProto sending PreparedPackage. This causing leaking error according #49. To reproduce simply create telegram api object:

`

        AppInfo appInfo = new AppInfo(yourapiid, "console", "1.0", "1.0", "en");
        TLApiState state = new TLApiState();
        api = new TelegramApi(state, appInfo, new ApiCallback() {
            @Override
            public void onAuthCancelled(TelegramApi api) {}
            @Override
            public void onUpdatesInvalidated(TelegramApi api) {}
            @Override
            public void onUpdate(TLAbsUpdates updates) {}
        });
        while (go) {
          //loop
        }

` Receiving 404 error cause calling onChannelBroken. On each fail response MTProto.this.contexts.notifyAll() will be called, that caused multiply creating PyroSelector by ConnectionFixerThread. Few minutes and everything crashes with java.io.IOException: Too many open files in system .

c0ldd commented 6 years ago

2018-04-12 11:27:57,354 | INFO | duller#602744093 | TechLogging | Scheduller:Prepare package: ping#7abe77ec of size 12 2018-04-12 11:27:57,355 | INFO | duller#602744093 | TechLogging | Scheduller:Prepare package: ping_delay_disconnect#f3427b8c of size 16 2018-04-12 11:27:57,355 | INFO | duller#602744093 | TechLogging | MTProto#1001#Scheduller:Building package 2018-04-12 11:27:57,357 | INFO | duller#602744093 | TechLogging | MTProto#1001#Scheduller:Adding package: #2 ping#7abe77ec (6543475777462075396, 1) 2018-04-12 11:27:57,357 | INFO | duller#602744093 | TechLogging | MTProto#1001#Scheduller:Adding package: #3 ping_delay_disconnect#f3427b8c (6543475777462075400, 3) 2018-04-12 11:27:57,357 | INFO | duller#602744093 | TechLogging | MTProto#1001#Scheduller:Sending Package (6543475777462075404, 4) 2018-04-12 11:27:57,358 | INFO | duller#602744093 | TechLogging | MTProto#1001#Scheduller:Single preparedPackage: #2 2018-04-12 11:27:57,358 | INFO | duller#602744093 | TechLogging | MTProto#1001:MessagePushed (#2): seqNo:4, msgId6543475777462075404 2018-04-12 11:27:57,518 | WARN | Selector Thread | TechLogging | MTProto#1001:OnError (#2): -404

talebipour commented 6 years ago

I think I have same problem which leads to same java.io.IOException: Too many open files in system. I used file handle leak detector (thanks to kuhsuke!) and found following trace for leakage:

1023 socket channel by thread:Selector Thread on Sun Apr 15 11:09:20 IRDT 2018

    at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:108)
    at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
    at java.nio.channels.SocketChannel.open(SocketChannel.java:145)
    at jawnae.pyronet.PyroClient.<init>(PyroClient.java:31)
    at jawnae.pyronet.PyroSelector.connect(PyroSelector.java:62)
    at jawnae.pyronet.PyroSelector.connect(PyroSelector.java:58)
    at org.telegram.mtproto.transport.TcpContext.lambda$connect$1(TcpContext.java:443)
    at org.telegram.mtproto.transport.TcpContext$$Lambda$8/493127745.run(Unknown Source)
    at jawnae.pyronet.PyroSelector.executePendingTasks(PyroSelector.java:89)
    at jawnae.pyronet.PyroSelector.select(PyroSelector.java:74)
    at jawnae.pyronet.PyroSelector.select(PyroSelector.java:66)
    at jawnae.pyronet.PyroSelector$1.run(PyroSelector.java:162)