Giter VIP home page Giter VIP logo

Comments (13)

om26er avatar om26er commented on June 1, 2024 1

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/[email protected]/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/[email protected]/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/[email protected]/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

from websocket.

savsgio avatar savsgio commented on June 1, 2024

Could you share your code? please

from websocket.

maxjust avatar maxjust commented on June 1, 2024

I just use this example https://github.com/fasthttp/websocket/tree/master/examples/chat/fasthttp

from websocket.

kirillDanshin avatar kirillDanshin commented on June 1, 2024

@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)

from websocket.

OPTIONPOOL avatar OPTIONPOOL commented on June 1, 2024

I'm having the same issue. Has anyone solved this?

from websocket.

savsgio avatar savsgio commented on June 1, 2024

Hi @OPTIONPOOL,

Could you explain your case, please?

from websocket.

OPTIONPOOL avatar OPTIONPOOL commented on June 1, 2024

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()
}

from websocket.

savsgio avatar savsgio commented on June 1, 2024

Which versions are you using of the websocket and fasthttp packages??

from websocket.

OPTIONPOOL avatar OPTIONPOOL commented on June 1, 2024

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

from websocket.

OPTIONPOOL avatar OPTIONPOOL commented on June 1, 2024

Any progress so far?

from websocket.

savsgio avatar savsgio commented on June 1, 2024

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?

from websocket.

azlan avatar azlan commented on June 1, 2024

@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

from websocket.

savsgio avatar savsgio commented on June 1, 2024

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

from websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.