after 5-6 min each time always after run application. whatsapp all this time running and screen not sleep
i'm facing the same problem. the error is coming from line 273 in conn.go
is it from whatsapp trying to block us T.T?
Maybe because of a huge amount a message to sync ?
Tried changing IP? Whatsapp number?
Yes i try change number whatsapp and golang app stay in my local pc and vps. But i cant might install and lauch emul android on vps with very good quality internet. But i do it all on one phone and one and one ip. I dont know how control quantity sync trying.
I will trying change ip and phone, after tryin i write it by result here
it seems that i'm able to fix it by modifying the keep alive interval at line 131, conn.go
go wac.keepAlive(20000, 90000) -> go wac.keepAlive(20000, 60000)
i guess whatsapp close the connection somewhere around one minute if no communication.
I didn't do something like go wac.keepAlive(10000, 20000) as i also don't want to send the keep alive signal too frequent which may lead to a blocking from whatsapp.
@jasontkh
all to good, but i receive this error after an indefinite period of time, i have low quality internet
error writing to socket: write tcp 192.168.1.22:49927->157.240.15.53:443: wsasend: An existing connection was forcibly closed by the remote host.
but on linux host i also reviece error 1006.
@jasontkh Your solution worked for me, Thanks. I didn't face this issue in my home network, but when deployed on server.
@hiwaleakshay how match parametrs you add in this function ?
I add 20000,60000 and all the same linux and windows host i recieve 1006
I'm not sure about working under Linux env, I'm still developing on my Mac. I guess it is a networking problem rather then OS problem. Let me get back after I test it on my Linux server.
And I think the code is not trying to reconnect after the network is down. I am trying to wrap it into another piece of small python code to take care of that.
@Jasontkh how parametrs you add in this function? I add 20000 and 60000.
This app correct worked only for high qualty unternet without timeouts ?
I used 20000,60000. I tested only for 10 mins, it looked normal.
You are right that the application does not handle time out. I tried to run the application, then unplug the LAN cable ---- nothing happened. No error even when I send a message. I guess this is the limitation of the web socket library of golang.
when client on timeout, server think what client disconnected and close session.
but client not know what is session has been closed and trying continue session but received error from server.
@bottookku Maybe this error should be handled in close handler in the same manner as unexpected close, meaning reconnection?
https://github.com/Rhymen/go-whatsapp/blob/c9a81e9578840e5c04c49c9e6126a1682faf22fc/conn.go#L167-L179
In that piece of code I'm getting code = 1000
It may be also handled externally, but then we should expose reconnect by renaming to Reconnect. And it would be great to create the Close function. I mentioned that in #111
As I mentioned in the previous issue (#98), I'm pretty sure this is caused by c9a81e9578840e5c04c49c9e6126a1682faf22fc. My program would stop working in 3 minutes after startup with that commit, but now that I reverted it, my program has been running fine for over a week.
The correct solution might be the keepalive delay change as @jasontkh suggested (I haven't tried that yet), but I don't think reconnecting is the correct solution.
I tested @jasontkh's shorter keepalive and it works. It's true that reconnects each minute is not the best solution.
My row 162 wss://web.whatsapp.com/ws is not wss://w3.web.whatsapp.com/ws
But i all the same i recieve 1006
Sorry i mistaken i need use old version. I will test it.
I think @tulir is right is solved for me
error writing to socket: write tcp 192.168.1.22:49194->169.60.79.32:443: wsasend: An existing connection was forcibly closed by the remote host.
panic: repeated read on failed websocket connection
goroutine 9 [running]:
github.com/gorilla/websocket.(Conn).NextReader(0x12c020c0, 0x9f1660, 0x12d11312, 0x2, 0x12d10060, 0x12c381c0)
C:/Users/botto/go/src/github.com/gorilla/websocket/conn.go:968 +0x2bc
github.com/gorilla/websocket.(Conn).ReadMessage(0x12c020c0, 0x0, 0x12caff60, 0x1, 0x1, 0x7b2200, 0x12d10030)
C:/Users/botto/go/src/github.com/gorilla/websocket/conn.go:1029 +0x25
github.com/Rhymen/go-whatsapp.(*Conn).readPump(0x12c44b40)
C:/Users/botto/go/src/github.com/Rhymen/go-whatsapp/conn.go:272 +0x5c
created by github.com/Rhymen/go-whatsapp.NewConn
it error i recieve if run go on local pc.. wsasend: An existing connection was forcibly closed by the remote host.
but on remote server VPS run go too same recieve 1006..
all it time phone my stay with me with my low quality internet.
go wac.keepAlive(20000, 90000)->go wac.keepAlive(20000, 60000)
i don't get 1006 error anymore, but my go-whatsapp only app, exit without any printed message
@codenoid How do you use/run go-whatsapp? Did you implement the Handler interface with its method HandleError?
normal way (based on example), i run with go run and(or) executing the compiled binary
yes @SchulteMK
//HandleError needs to be implemented to be a valid WhatsApp handler
func (*waHandler) HandleError(err error) {
fmt.Fprintf(os.Stderr, "error occoured: %v", err)
}
my bad, sorry it was the <-time.After(5 * time.Minute)
In #114 I reworked the whole connection including the readPump. I decided to close the connection on a connection failure and emit an error through the handler. You can check, if it is an connection failure error and restore the connection with wac.Restore(). I included an example implementation of most of the new features in example/receiveMessages.
I will test if the connction holds up during the night. If it does I think I can merge the PR
yeah, solved with go wac.keepAlive(20000, 60000) , otherwise if disconnected, you can use wac.Restore() or restart your application
level=error msg="connection to WhatsApp servers failed: websocket: close 1006 (abnormal closure): unexpected EOF" prefix=whatsapp
level=error msg="SendMessage failed: could not send proto: failed to write message: error writing to websocket: write tcp x.x.x.x:x->x.x.x.x:443: write: connection reset by peer" prefix=gateway
Using go-whatsapp with matterbridge. Connection fails after a time when mobile application goes offline.
Most helpful comment
it seems that i'm able to fix it by modifying the keep alive interval at line 131, conn.go
go wac.keepAlive(20000, 90000)->go wac.keepAlive(20000, 60000)i guess whatsapp close the connection somewhere around one minute if no communication.
I didn't do something like
go wac.keepAlive(10000, 20000)as i also don't want to send the keep alive signal too frequent which may lead to a blocking from whatsapp.