kataras / go-websocket

:speaker: Deprecated. Use https://github.com/kataras/neffos instead
MIT License
59 stars 16 forks source link

Cannot alter WebsocketWriteTimeout #27

Closed bluedaniel closed 7 years ago

bluedaniel commented 7 years ago

With Iris v6.1.4 it seems I can't change the socket timeout from 15s.

I've got 2 sockets running and the code looks something like:

api := iris.New()
ws := iris.NewWebsocketServer(api)
ws.Config = iris.WebsocketConfiguration{Endpoint: "/ws/endpoint1", WriteTimeout: 60 * time.Second}
ws.OnConnection(func(ctx iris.WebsocketConnection) {
    ...
})

I've also tried api := iris.New(iris.OptionWebsocketWriteTimeout(60 * time.Second)) and a number of other option setters but to no avail yet.

The socket closes exactly 15s each time.

ghost commented 7 years ago

Hmmm that's strange @bluedaniel , let me fix it, but I want to let you know that iris is compatible with any websocket library (including socket.io , you can see an example here)

ghost commented 7 years ago

@bluedaniel on my tests is working ...

Could you please remove your $GOPATH/src/github.com/kataras/go-websocket and do: go get github.com/kataras/go-websocket , test again your code snippet and also this code snippet: ws.Config = iris.DefaultWebsocketConfiguration(); ws.Config.Endpoint="/ws/endpoint1"; ws.Config.WriteTimeout= 60 *time.Second (because NewWebsocketServer doesn't defaults the configs as the iris.New does, this will be fixed on the next version) and tell me the results please?

bluedaniel commented 7 years ago

I'm still getting a close event at 15s.

bluedaniel commented 7 years ago

Not sure if this is helpful but the disconnection happens 15 seconds after the last write to the socket.

Code:

wsTest := iris.NewWebsocketServer(api)

wsTest.Config = iris.DefaultWebsocketConfiguration()
wsTest.Config.Endpoint = "/ws/endpoint1"
wsTest.Config.WriteTimeout = 60 * time.Second

wsTest.OnConnection(func(ctx iris.WebsocketConnection) {
  fmt.Println(time.Now().Format("01/02 - 15:04:05") + " - connected")
  ctx.OnMessage(func(msg []byte) {
    fmt.Println(time.Now().Format("01/02 - 15:04:05") + " - msg:" + string(msg))
  })
  ctx.OnDisconnect(func() {
    fmt.Println(time.Now().Format("01/02 - 15:04:05") + " - disconnected!")
  })
})

Example output of me pinging it a few times.

02/14 - 17:46:55 - connected
02/14 - 17:47:10 - disconnected!
[IRIS] 2017/02/14 17:47:10 02/14 - 17:47:10 200 15.002598344s 172.18.0.1 GET /ws/endpoint1

02/14 - 17:47:22 - connected
02/14 - 17:47:26 - msg:test
02/14 - 17:47:30 - msg:test
02/14 - 17:47:34 - msg:test
02/14 - 17:47:49 - disconnected!
[IRIS] 2017/02/14 17:47:49 02/14 - 17:47:49 200 27.604419261s 172.18.0.1 GET /ws/endpoint1
ghost commented 7 years ago

You have right, I'm sorry, wait for fix in the next minutes

ghost commented 7 years ago

@bluedaniel fixed, it was the most idiot-fix I had to do, it was about the order, we first called Handler() and after setting configuration ( previous go-websocket versions libs worked but latest works different for performance boost). I did pushed the 'fix' to the iris so you can upgrade just iris with go get -u github.com/kataras/iris.

Thanks you

ghost commented 7 years ago

@bluedaniel If you upgrade the go get -u github.com/kataras/go-websocket now, you can set 0 as WriteTimeout and ReadTimeout to disable the timeout at all :)