Closed maxjust closed 1 year ago
Could you share your code? please
I just use this example https://github.com/fasthttp/websocket/tree/master/examples/chat/fasthttp
@savsgio @maxjust I've managed to reproduce the issue.
just run this script in a browser console several times:
for (let i = 0; i < 40000; i++) {
(new WebSocket(`ws://${document.location.host}/ws`)).onopen = () => (
conn.send('asdfasdf')
)
}
note: browser console should be opened in the context of this example page (e.g. localhost:8080)
I'm having the same issue. Has anyone solved this?
Hi @OPTIONPOOL,
Could you explain your case, please?
Hi @OPTIONPOOL,
Could you explain your case, please?
This is my code, and the crash's stack trace is exactly the same as the above example starting from conn.WriteMessage.
if conn != nil {
connectionMutex.Lock()
err := conn.WriteMessage(1, []byte(response))
connectionMutex.Unlock()
}
Which versions are you using of the websocket and fasthttp packages??
Which versions are you using of the websocket and fasthttp packages??
These are the packages that I am currently using.
github.com/fasthttp/websocket v1.4.1 github.com/valyala/fasthttp v1.8.0 github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87
Any progress so far?
I have been researching about it but I don't get to reproduce the error in my laptop. Could you share your code and the panic stack trace, please?
@OPTIONPOOL, my quick solution is
if c == nil {
return errors.New("Connection already dropped")
}
at https://github.com/fasthttp/websocket/blob/master/conn.go#L752
I see this issue in 1.5.1, I don't know the exact reason, though it is possible my automatic ping code tries to send a ping message even though the connection was closed. Wonder if there is a definitive way to know if the connection has closed ?
Feb 13 21:55:18 Hub: panic: runtime error: invalid memory address or nil pointer dereference
Feb 13 21:55:18 Hub: [signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x3863ec]
Feb 13 21:55:18 Hub: goroutine 301 [running]:
Feb 13 21:55:18 Hub: github.com/valyala/fasthttp.(*hijackConn).SetWriteDeadline(0x0?, {0x40025e720c?, 0x40025cf628?, 0x0?})
Feb 13 21:55:18 Hub: <autogenerated>:1 +0x2c
Feb 13 21:55:18 Hub: github.com/fasthttp/websocket.(*Conn).write(0x40023bef20, 0x9, {0x40001869e0?, 0x400349f800?, 0x0?}, {0x40025e720c, 0x2, 0x402}, {0x0, 0x0, ...})
Feb 13 21:55:18 Hub: /home/om26er/go/pkg/mod/github.com/fasthttp/websocket@v1.5.1/conn.go:416 +0x190
Feb 13 21:55:18 Hub: github.com/fasthttp/websocket.(*messageWriter).flushFrame(0x4002837ec8, 0x1, {0x0?, 0x19b2c?, 0x4003227748?})
Feb 13 21:55:18 Hub: /home/om26er/go/pkg/mod/github.com/fasthttp/websocket@v1.5.1/conn.go:661 +0x360
Feb 13 21:55:18 Hub: github.com/fasthttp/websocket.(*Conn).WriteMessage(0x40023bef20, 0x448a48?, {0x0, 0x0, 0x0})
Feb 13 21:55:18 Hub: /home/om26er/go/pkg/mod/github.com/fasthttp/websocket@v1.5.1/conn.go:815 +0xfc
Feb 13 21:55:18 Hub: github.com/code/connect/transport.(*FastHTTPPeer).Ping(0x53a82eb794f2f?, {0x0?, 0x554289?, 0x0?})
Feb 13 21:55:18 Hub: /home/om26er/scm/scratch/connect/transport/fasthttpwebsocketpeer.go:89 +0x38
Feb 13 21:55:18 Hub: github.com/code/connect/server.(*ConnectionHandler).startAutoPinger.func1()
Feb 13 21:55:18 Hub: /home/om26er/scm/scratch/connect/server/connectionhandler.go:333 +0xd4
Feb 13 21:55:18 Hub: created by github.com/code/connect/server.(*ConnectionHandler).startAutoPinger
Feb 13 21:55:18 Hub: /home/om26er/scm/scratch/connect/server/connectionhandler.go:323 +0xac
Hi @om26er,
Sorry for my delayed answer!
Could you share the ping handler code, please?
Remember that websocket connections are not safe concurrent, so if you are starting a custom ping handler in a second gorutine into the upgrader you will get race conditions, so you must use this to ping connections (https://pkg.go.dev/github.com/fasthttp/websocket#Conn.SetPingHandler)
Also see: https://pkg.go.dev/github.com/fasthttp/websocket#hdr-Concurrency
a random panic with this stack trace, cant reproduce it just a random, and happen from time to time
can anybody help or maybe have an idea how to fix?