AmarnathCJD / gogram

Full-native implementation of MTProto protocol on Golang.
GNU General Public License v3.0
207 stars 41 forks source link

recreating connection: reqPQ: nonce mismatch #43

Closed wind-hx closed 1 year ago

wind-hx commented 1 year ago

Example

log.Printf("init...\n")
client, _ := telegram.NewClient(telegram.ClientConfig{
    AppID:   int32(apiId),
    AppHash: apiHash,
})
client.Connect()
client.ImportRawSession(session.AuthKey, session.AuthKeyHash, session.Addr, int(session.DcID), int32(apiId))
log.Printf("init end...\n")
client.GetMe()

Logs

2023/05/11 17:04:06 call getSignInUser...
2023/05/11 17:04:06 init...
2023/05/11 17:04:06 gogram - mtproto - Info - Connecting to [149.154.167.91:443] - <TCPFull> ...
2023/05/11 17:04:06 gogram - mtproto - Info - Connection to [149.154.167.91:443] - <TCPFull> established
2023/05/11 17:04:13 gogram - mtproto - Error - reconnecting error: recreating connection: reqPQ: nonce mismatch
2023/05/11 17:05:18 init end...
2023/05/11 17:06:23 gogram - mtproto - Error - reconnecting error: recreating connection: reqPQ: nonce mismatch

got invalid response type: *objects.ResPQ
/Users/feit/Project/telegram-transport/vendor/github.com/amarnathcjd/gogram/telegram/methods_gen.go:11159 (0x12d6044)
        (*Client).UsersGetFullUser: panic("got invalid response type: " + reflect.TypeOf(responseData).String())
/Users/feit/Project/telegram-transport/vendor/github.com/amarnathcjd/gogram/telegram/users.go:11 (0x12dd8ca)
        (*Client).GetMe: resp, err := c.UsersGetFullUser(&InputUserSelf{})
/Users/feit/Project/telegram-transport/src/mtproto/api.go:53 (0x12f4445)
        TGetMe: user, err := client.GetMe()
/Users/feit/Project/telegram-transport/src/service/client.go:15 (0x12f4b93)
        GetSignInUser: user, err := mtproto.TGetMe(tag, apiId, apiHash, proxyAddress, proxyUsername, proxyPassword)
/Users/feit/Project/telegram-transport/src/controller/client.go:40 (0x1414e5c)
        GetSignInUser: result := service.GetSignInUser(tag, apiId, apiHash, proxyAddress, proxyUsername, proxyPassword)
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/context.go:174 (0x140ea01)
        (*Context).Next: c.handlers[c.index](c)
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/recovery.go:102 (0x140e9ec)
        CustomRecoveryWithWriter.func1: c.Next()
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/context.go:174 (0x140db26)
        (*Context).Next: c.handlers[c.index](c)
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/logger.go:240 (0x140db09)
        LoggerWithConfig.func1: c.Next()
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/context.go:174 (0x140cbaa)
        (*Context).Next: c.handlers[c.index](c)
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/gin.go:620 (0x140c831)
        (*Engine).handleHTTPRequest: c.Next()
/Users/feit/Project/telegram-transport/vendor/github.com/gin-gonic/gin/gin.go:576 (0x140c4dc)
        (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/go/src/net/http/server.go:2936 (0x12a4b35)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1995 (0x12a1451)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_amd64.s:1598 (0x1066920)
        goexit: BYTE    $0x90   // NOP

What is causing the program to crash?Judging from the log printing time, there is a long time of no response in the middle.

RoseLoverX commented 1 year ago

check your system clock

wind-hx commented 1 year ago

My system time is fine

wind-hx commented 1 year ago

Is it related to the operating system? The time is automatically obtained by the system when it is connected to the Internet.

TAMILVIP007 commented 1 year ago

@wind-hx

wind-hx commented 1 year ago

@wind-hx

?

AmarnathCJD commented 1 year ago

Is it related to the operating system? The time is automatically obtained by the system when it is connected to the Internet.

I couldn't recreate the error

what's your OS, timezone etc the randombyte gen is based on system time Unix so that must be the error The lib has been tested on Windows 10,11 and major linux distros

AmarnathCJD commented 1 year ago

@AmarnathCJD Maybe post the full code

wind-hx commented 1 year ago

I am Mac OS operating system

package main

import (
    "log"

    "github.com/amarnathcjd/gogram/telegram"
)

func main() {
    log.Printf("init...\n")
    appID := int32(611335)
    appHash := "d524b414d21f4d37f08684c1df41ac9c"
    client, _ := telegram.NewClient(telegram.ClientConfig{
        AppID:   appID,
        AppHash: appHash,
    })
    client.Connect()
    authKey := []byte{188, 193, 215, 239, 216, 225, 180, 195, 131, 110, 125, 151, 248, 183, 61, 66, 108, 245, 107, 152, 157, 35, 224, 107, 30, 238, 17, 99, 79, 242, 39, 148, 148, 163, 151, 101, 126, 35, 158, 227, 144, 112, 79, 175, 196, 79, 213, 228, 219, 72, 17, 81, 141, 185, 223, 217, 98, 102, 200, 127, 50, 233, 38, 131, 19, 51, 2, 0, 81, 229, 83, 18, 125, 96, 223, 147, 202, 202, 80, 218, 70, 242, 211, 174, 42, 77, 114, 179, 43, 161, 246, 141, 27, 183, 192, 111, 203, 219, 14, 80, 175, 129, 158, 97, 125, 113, 106, 38, 139, 212, 206, 36, 228, 139, 37, 112, 251, 2, 188, 234, 125, 131, 112, 200, 141, 227, 31, 236, 200, 240, 129, 89, 49, 191, 244, 109, 205, 226, 186, 10, 132, 8, 71, 146, 89, 240, 99, 70, 197, 186, 115, 124, 161, 12, 182, 124, 209, 140, 147, 87, 60, 213, 101, 23, 177, 37, 82, 108, 64, 173, 167, 10, 4, 197, 168, 237, 230, 61, 138, 44, 249, 24, 154, 136, 47, 215, 158, 119, 147, 213, 204, 89, 241, 123, 235, 34, 207, 133, 224, 120, 115, 52, 253, 99, 152, 117, 8, 154, 207, 124, 231, 140, 134, 54, 86, 54, 126, 124, 165, 19, 113, 219, 142, 103, 103, 97, 148, 97, 36, 147, 33, 238, 8, 157, 213, 150, 161, 100, 131, 164, 255, 6, 1, 178, 217, 182, 51, 29, 12, 161, 117, 250, 80, 64, 36, 123}
    authKeyHash := []byte{210, 193, 149, 11, 102, 194, 206, 136}
    addr := "91.108.56.126:443"
    dcId := 5
    client.ImportRawSession(authKey, authKeyHash, addr, dcId, appID)
    log.Printf("init end...\n")
    user, err := client.GetMe()
    if err != nil {
        log.Println("error: ", err)
        return
    }
    log.Println("user: ", user)
}
2023/05/12 13:48:46 init...
2023/05/12 13:48:46 gogram - mtproto - Info - Connecting to [149.154.167.91:443] - <TCPFull> ...
2023/05/12 13:48:46 gogram - mtproto - Info - Connection to [149.154.167.91:443] - <TCPFull> established
2023/05/12 13:48:48 init end...

Here is my full code with full log info

wind-hx commented 1 year ago

Is there an error in the code I provided?

wind-hx commented 1 year ago

Is it related to the operating system? The time is automatically obtained by the system when it is connected to the Internet.

I couldn't recreate the error

what's your OS, timezone etc the randombyte gen is based on system time Unix so that must be the error The lib has been tested on Windows 10,11 and major linux distros

My country is China and my time zone is GMT+8

AmarnathCJD commented 1 year ago

@wind-hx It's something related to macos then lemme try seeding the bytes generator but idh a mac system to test it.

wind-hx commented 1 year ago

How can I solve this problem?

AmarnathCJD commented 1 year ago

@wind-hx Try seeding the default crypto/rand seeder maybe before client starts

AmarnathCJD commented 1 year ago

@AmarnathCJD I would need time to setup a macos vm to check the issue

AmarnathCJD commented 1 year ago

stale issue