Git Product home page Git Product logo

Comments (2)

thomaspoignant avatar thomaspoignant commented on June 5, 2024

Hey @bearrito thanks for sharing this.
I would be interested to understand how you reproduce it because this is not something occurring on my side.

from go-feature-flag.

bearrito avatar bearrito commented on June 5, 2024

It looks like what is happening is a concurrent write to the webscocket connection

https://github.com/thomaspoignant/go-feature-flag/blob/main/cmd/relayproxy/controller/ws_flag_change.go#L87
and

https://github.com/thomaspoignant/go-feature-flag/blob/main/cmd/relayproxy/service/websocket.go#L45

==================
WARNING: DATA RACE
Read at 0x00c0001f0338 by goroutine 32:
  github.com/gorilla/websocket.(*Conn).beginMessage()
      /home/bstrausser/go/pkg/mod/github.com/gorilla/[email protected]/conn.go:492 +0x6d
  github.com/gorilla/websocket.(*Conn).WriteMessage()
      /home/bstrausser/go/pkg/mod/github.com/gorilla/[email protected]/conn.go:779 +0x17b
  github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/controller.(*wsFlagChange).pingPongLoop()
      /home/bstrausser/Git/go-feature-flag/cmd/relayproxy/controller/ws_flag_change.go:87 +0x35e
  github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/controller.(*wsFlagChange).Handler.func3()
      /home/bstrausser/Git/go-feature-flag/cmd/relayproxy/controller/ws_flag_change.go:58 +0x71

Previous write at 0x00c0001f0338 by goroutine 27:
  github.com/gorilla/websocket.(*Conn).NextWriter()
      /home/bstrausser/go/pkg/mod/github.com/gorilla/[email protected]/conn.go:538 +0x177
  github.com/gorilla/websocket.(*Conn).WriteJSON()
      /home/bstrausser/go/pkg/mod/github.com/gorilla/[email protected]/json.go:24 +0x7e
  github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/service.(*websocketServiceImpl).BroadcastFlagChanges()

I can force this by doing one of two things

Number 1
Add a tight loop at the https://github.com/thomaspoignant/go-feature-flag/blob/main/cmd/relayproxy/controller/ws_flag_change_test.go#L120

for i := 0; i < 10000; i++ {
				websocketService.BroadcastFlagChanges(tt.flagChange)
				_, _, err := ws.ReadMessage()
				assert.NoError(t, err)
			}

Set the ping pong frequency to something high https://github.com/thomaspoignant/go-feature-flag/blob/main/cmd/relayproxy/controller/ws_flag_change.go#L77 I did 100ms

Eventually the Broadcast and ping-pong will race. I takes a lot of loops and fast ping-pong rate so if this is real I bet this is rare in production.

Number 2
A sleep statement or debugger breakpoint before https://github.com/thomaspoignant/go-feature-flag/blob/main/cmd/relayproxy/controller/ws_flag_change_test.go#L121 will also cause it. I assume this stalls the broadcast write and gives time to the ping-ponger.

from go-feature-flag.

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.