cjongseok / mtproto

Telegram MTProto and its proxy (over gRPC) in Go (golang). API Layer: 71
Apache License 2.0
151 stars 20 forks source link

Program hangs when second session tries to start #23

Open handlerug opened 5 years ago

handlerug commented 5 years ago

I am trying to implement multi-account feature in my program. I define array of accounts and try to login:

// Account represents Telegram account.
type Account struct {
    Phone      string
    ConfigPath string
    // ...
}
accs := make(map[string]*Account)
accs[args[0]] = &Account{
    Phone:      args[0],
    ConfigPath: os.Args[1],
}
accs[args[0]].Login() // it works
accs[args[1]] = &Account{
    Phone:      args[1],
    ConfigPath: os.Args[1],
}
accs[args[1]].Login() // now it hangs

Logs:

... first account logs ...
... now second account tries to login
2019/01/27 23:42:54 [MM 290413704] start
2019/01/27 23:42:54 [MM 290413704] newsession to  149.154.167.50:443
here it hangs

Does your library support multiple sessions? I explored your code and I think those accounts should use different managers. If you need the Account.Login method's code, I can upload it as gist (this is the code from SimpleShell, with small changes). Thank you a lot for this beautiful library!

altfoxie commented 5 years ago

Ha-ha, classic.

cjongseok commented 5 years ago

@handlerug Multi-sessions are not supported in this library. I left a room for the multi-sessions in manager but it is not implemented yet. As you said multi-managers can work with multi-sessions, but I didn't try that.

handlerug commented 5 years ago

Thank you for reply! I already use multiple managers for accounts, but as I described in the issue, this approach doesn't work for unknown reason :(

handlerug commented 5 years ago

Also, I explored library code and found out that it hangs in manager.NewAuthentication(...) when it tries to get the response from Telegram server:

image

Maybe Telegram servers ignore this request, and Go http client just hangs (because it's without timeout by default)?

cjongseok commented 5 years ago

@handlerug When manager.NewAuthentication(...) is called, manager's event loop handles newsession event at this line. You can compare your auth progress with printed logs I think. I hope this can help you to make multi-sessions work.

Thanks for your participations for multi-session uses in various ways. If it finally work with multi managers, it would be cool. But if not, I think reserving it to the next version of the lib would be the better way. In the following major update, I will seriously consider it together with other feature requests.

handlerug commented 5 years ago

Woah, a month has already passed since last reply to this issue. I tried looking at the code, and it hangs at newSession(...) if logs don't lie. I don't know why, so I forgot about this issue. Maybe there are conflicting connections (but Telegram clients support multi-accounts)?