I've ran into some strange websockets behaviour today and seek for some help from comunity to understand what can be the cause.
I've been trying to implement some simple webservice using websockets (from gorillas toolkit). Everything worked fine at home (I'm using macOS there), but when I pulled the latest version from git at the office (we have Windows here) - I was surprised to see that the very same code gives different result. After some time connection timeouts, pushing all messages to the client, and closes.
After some meddling with my code I couldn't figure out what was wrong and decided to test gorilla's chat example (https://github.com/gorilla/websocket/tree/master/examples/chat)
Same behavior. You send some messages to chat, no reaction, 60 seconds after - you finally see:
test1
test2
test3
Connection closed.
Any ideas what can cause this?
My repo (just in case): https://github.com/konart/gokoi/tree/websockets
评论:
konart:
SilentWeaponQuietWar:Okay I figured it out. All ports except for 15000 are closed.
Mark as SOLVED. :)
konart:the ListenAndServe method doesn't let you explicitly set timeouts and other config settings. For that very reason, it's usually suggested to use http.Server instead
https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
daveddev:I don't think this is the case though. First of all timeout happens after 60 seconds, so I believe this is the "// Time allowed to read the next pong message from the peer." or a "pongWait" variable that is used for setting ReadDeadline and PongHandler.
Anyway - I've tried doing it this way before (just in case):
srv := &http.Server{ Handler: r, Addr: "127.0.0.1:8000", WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second, } log.Fatal(srv.ListenAndServe())
Same outcome.
konart:If you are using a reverse proxy to pass off processing, you may be running into a timeout defined as a default within that system. This came up as a problem for me recently (nginx - proxy_read_timeout). I hope this helps.
Thanks, I'm gonna keep it in mind, but for now - I figured it out. Blocked ports were the problem
