Git Product home page Git Product logo

Comments (7)

knadh avatar knadh commented on August 27, 2024 3

@oguzhane We were experimenting along similar lines and stumbled upon this thread. SetReadDeadline() does not work unfortunately as the micro timeouts leave the connection in a dirty state (partially read bytes maybe) when there's heavy traffic, causing subsequent reads to fail because of malformed messages.

from ws.

gobwas avatar gobwas commented on August 27, 2024

Hi @kenfoo,

This is intended behaviour of this method – that is, the word "Data" means exactly what you have discovered – read the data message, not the control.

When using epoll somehow wsutil helpers is not the best way to deal with frames.

from ws.

oguzhane avatar oguzhane commented on August 27, 2024

@kenfoo
maybe, one of the ways below can help you to avoid blocking goroutine.

you could use SetReadDeadline to stop waiting reading data, if it fits your case.

..
netConn.SetReadDeadline(time.Now().Add(50 * time.Millisecond))
data, opCode, err := wsutil.ReadClientData(netConn)
if os.IsTimeout(err) {
  ..
}

Another way could be exposing EWOULDBLOCK error by reading data directly from file descriptor with syscall.Read.

type SysConn struct {
  ..
  fd int
}

func (s SysConn) Read(p []byte) (int, error) {
        ..
	n, err := syscall.Read(s.fd, p)
        ..
	return n, err
}

data, opCode, err := wsutil.ReadClientData(sysConn)
if err  == syscall.EAGAIN {
  ..
}

Would be helpful to check implementation of *netFD.Read to have graceful handling.
see:
https://golang.org/src/net/fd_unix.go
https://golang.org/src/internal/poll/fd_unix.go

from ws.

oguzhane avatar oguzhane commented on August 27, 2024

@knadh I have ended up going for the approach reading data from the file descripter by using syscall.RawConn. However, i have not tested it under high load of traffic yet.
The problem with this approach is it does not work well with crypto/tls since standart Golang TLS implementation does not support event-based mechanism.

from ws.

knadh avatar knadh commented on August 27, 2024

@oguzhane we tried reading directly from the file descriptor and under high loads, it ran into the same issues with malformed / partial messages.

from ws.

kenfoo avatar kenfoo commented on August 27, 2024

Hi. If it is of any help to anyway, we ended up simply reimplementing what wsutil.readData did, but modified it such that it doesn't block or loop, and instead returns the bytes, the opcode and error in all cases.

from ws.

knadh avatar knadh commented on August 27, 2024

@kenfoo we attempted this unsuccessfully. It'd be nice if you could share your solution!

from ws.

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.