Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data race #1287

Closed
isnlan opened this issue Jun 25, 2019 · 1 comment
Closed

data race #1287

isnlan opened this issue Jun 25, 2019 · 1 comment

Comments

@isnlan
Copy link

isnlan commented Jun 25, 2019

`package main

import (
"fmt"

"github.com/kataras/iris"
"github.com/kataras/iris/websocket"

)

func main() {
app := iris.New()

app.Get("/", func(ctx iris.Context) {
	ctx.ServeFile("websockets.html", false) // second parameter: enable gzip?
})

setupWebsocket(app)

// x2
// http://localhost:8080
// http://localhost:8080
// write something, press submit, see the result.
app.Run(iris.Addr(":8080"))

}

func setupWebsocket(app *iris.Application) {
// create our echo websocket server
ws := websocket.New(websocket.Config{
// These are low-level optionally fields,
// user/client can't see those values.
ReadBufferSize: 1024,
WriteBufferSize: 1024,
// only javascript client-side code has the same rule,
// which you serve using the ws.ClientSource (see below).
EvtMessagePrefix: []byte("my-custom-prefix:"),
})
ws.OnConnection(handleConnection)

// register the server on an endpoint.
// see the inline javascript code in the websockets.html, this endpoint is used to connect to the server.
app.Get("/echo", ws.Handler())

// serve the javascript built'n client-side library,
// see websockets.html script tags, this path is used.

}

func handleConnection(c websocket.Connection) {
// Read events from browser
c.On("chat", func(msg string) {
// Print the message to the console, c.Context() is the iris's http context.
fmt.Printf("%s sent: %s\n", c.Context().RemoteAddr(), msg)
// Write message back to the client message owner with:
// c.Emit("chat", msg)
// Write message to all except this client with:
c.To(websocket.Broadcast).Emit("chat", msg)
})
}
`

log:
Now listening on: http://localhost:8080
Application started. Press CTRL+C to shut down.

WARNING: DATA RACE
Read at 0x00c0003fc038 by goroutine 20:
github.com/kataras/iris/websocket.(*connection).startPinger.func2()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:346 +0x89

Previous write at 0x00c0003fc038 by goroutine 18:
github.com/kataras/iris/websocket.(*Server).Disconnect()
/opt/gopath/src/github.com/kataras/iris/websocket/server.go:429 +0xc6
github.com/kataras/iris/websocket.(*connection).startReader.func2()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:592 +0xc5
github.com/kataras/iris/websocket.(*connection).startReader()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:413 +0x2e7
github.com/kataras/iris/websocket.(*connection).Wait()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:581 +0x98
github.com/kataras/iris/websocket.(*Server).Handler.func1()
/opt/gopath/src/github.com/kataras/iris/websocket/server.go:108 +0x152
github.com/kataras/iris/context.Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:922 +0xa5
github.com/kataras/iris/context.(*context).Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:1094 +0x62
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest()
/opt/gopath/src/github.com/kataras/iris/core/router/handler.go:227 +0x721
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:84 +0xc4
github.com/kataras/iris/core/router.(*Router).ServeHTTP()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:161 +0x69
net/http.serverHandler.ServeHTTP()
/opt/go/src/net/http/server.go:2774 +0xce
net/http.(*conn).serve()
/opt/go/src/net/http/server.go:1878 +0x811

Goroutine 20 (running) created at:
github.com/kataras/iris/websocket.(*connection).startPinger()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:342 +0xdb
github.com/kataras/iris/websocket.(*connection).Wait()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:578 +0x8a
github.com/kataras/iris/websocket.(*Server).Handler.func1()
/opt/gopath/src/github.com/kataras/iris/websocket/server.go:108 +0x152
github.com/kataras/iris/context.Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:922 +0xa5
github.com/kataras/iris/context.(*context).Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:1094 +0x62
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest()
/opt/gopath/src/github.com/kataras/iris/core/router/handler.go:227 +0x721
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:84 +0xc4
github.com/kataras/iris/core/router.(*Router).ServeHTTP()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:161 +0x69
net/http.serverHandler.ServeHTTP()
/opt/go/src/net/http/server.go:2774 +0xce
net/http.(*conn).serve()
/opt/go/src/net/http/server.go:1878 +0x811

Goroutine 18 (finished) created at:
net/http.(*Server).Serve()
/opt/go/src/net/http/server.go:2884 +0x4c4
github.com/kataras/iris/core/host.(*Supervisor).Serve.func1()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:220 +0x83
github.com/kataras/iris/core/host.(*Supervisor).supervise()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:192 +0x4c
github.com/kataras/iris/core/host.(*Supervisor).Serve()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:220 +0x78
github.com/kataras/iris/core/host.(*Supervisor).ListenAndServe()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:232 +0x86
github.com/kataras/iris.Addr.func1()
/opt/gopath/src/github.com/kataras/iris/iris.go:666 +0x124
github.com/kataras/iris.(*Application).Run()
/opt/gopath/src/github.com/kataras/iris/iris.go:821 +0x16d
main.main()
/opt/gopath/src/stu/main.go:23 +0x144

@kataras
Copy link
Owner

kataras commented Jun 25, 2019

Look the #1175 and the https://github.com/kataras/neffos for more about websockets, and I spoke about the websockets at this opened issue as well: #1283

@kataras kataras added this to the v11.2.0 milestone Jun 25, 2019
@kataras kataras closed this as completed Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants