Giter Site home page Giter Site logo

[BUG] If `deadline` argument to `WriteControl` is `deadline.IsZero()` then 1000 hours (~41 days) are used as unexpected and undocumented fallback about websocket HOT 2 OPEN

JannikGM avatar JannikGM commented on June 16, 2024 1
[BUG] If `deadline` argument to `WriteControl` is `deadline.IsZero()` then 1000 hours (~41 days) are used as unexpected and undocumented fallback

from websocket.

Comments (2)

jaitaiwan avatar jaitaiwan commented on June 16, 2024

Champion @JannikGM thank you. I'm taking a look at this now.

from websocket.

jaitaiwan avatar jaitaiwan commented on June 16, 2024

Nothing in the RFC seems to indicate any sane value for this. I don't know of any websocket extensions that need to be accounted for in any changes here.

It appears to me that this code is used in both client and server connections, so this probably is a more important function when it comes to clients being unable to write to the server.

Based on that information I think that the following actions should be taken:

  1. The default is documented as a warning
  2. Any examples should be updated to include setting this deadline to a sane standard
  3. This issue should be left open and marked for a v2 as changing this could be a nasty surprise for implementors that don't know about this

from websocket.

GreenMarmot avatar GreenMarmot commented on June 16, 2024

In the Go ecosystem, a zero value for deadline is usually taken to mean no deadline, not a deadline at the beginning of time. We know that's the intent here because the function sets the deadline on the network connection. A zero deadline on the network connection means no deadline.

A deadline in 41 days is not the same thing as no deadline, but it's a good approximation for most applications. Close the gap between what this package does and the expectations for deadlines by using the following code:

if deadline.IsZero() {
	<-c.mu
} else {
	d = time.Until(deadline)
	if d < 0 {
		return errWriteTimeout
	}
	select {
	case <-c.mu:
	default:
		timer := time.NewTimer(d)
		select {
		case <-c.mu:
			timer.Stop()
		case <-timer.C:
			return errWriteTimeout
		}
	}
}

With timeout of 41 days, it's unlikely that an application developer wrote code to rely on the undocumented timeout. It's not practical to test.

To trigger the 41 day timeout, another goroutine must be blocked for 41 days on write to the network connection. I'd expect the blocked write on a network connection to return an error before the 41 days elapses.

You will not break anything by updating to the code above. There will be no nasty surprises. You will not fix a problem that comes up in practice, but the code will be more correct and it will feel good to remove that weird constant from the code.

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.