Windows websockets timeout

polaris · 2017-03-13 20:00:04 · 640 次点击    
这是一个分享于 2017-03-13 20:00:04 的资源,其中的信息可能已经有所发展或是发生改变。

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:

Okay I figured it out. All ports except for 15000 are closed.

Mark as SOLVED. :)

SilentWeaponQuietWar:

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/

konart:

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.

daveddev:

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.

konart:

Thanks, I'm gonna keep it in mind, but for now - I figured it out. Blocked ports were the problem


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

640 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传