grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
343 stars 41 forks source link

Data race on frameNavigated #160

Closed inancgumus closed 11 months ago

inancgumus commented 2 years ago

Discovered by #141.

129 will possibly fix this:

--- PASS: TestPageGotoDataURI (4.05s)
858: running [Created by common.(*FrameSession).initEvents @ frame_session.go:206] Race write @ 0xc00148ea48
    common frame_manager.go:195 (*FrameManager).frameNavigated()
    common frame_session.go:593 (*FrameSession).onFrameNavigated()
    common frame_session.go:230 (*FrameSession).initEvents.func1()
861: finished [Created by common.(*Frame).startNetworkIdleTimer @ frame.go:283] Race read @ 0xc00148ea48
    common frame.go:242         (*Frame).recalculateLifecycle()
    common frame_manager.go:149 (*FrameManager).frameLifecycleEvent()
    common frame.go:288         (*Frame).startNetworkIdleTimer.func1()
==================
WARNING: DATA RACE
Write at 0x00c00099d468 by goroutine 894:
  github.com/grafana/xk6-browser/common.(*FrameManager).frameNavigated()
      /Users/inanc/grafana/xk6-browser2/common/frame_manager.go:195 +0x3e4
  github.com/grafana/xk6-browser/common.(*FrameSession).onFrameNavigated()
      /Users/inanc/grafana/xk6-browser2/common/frame_session.go:593 +0x36a
  github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
      /Users/inanc/grafana/xk6-browser2/common/frame_session.go:230 +0x7d0

Previous read at 0x00c00099d468 by goroutine 876:
  github.com/grafana/xk6-browser/common.(*Frame).recalculateLifecycle()
      /Users/inanc/grafana/xk6-browser2/common/frame.go:242 +0x334
  github.com/grafana/xk6-browser/common.(*FrameManager).frameLifecycleEvent()
      /Users/inanc/grafana/xk6-browser2/common/frame_manager.go:149 +0x72
  github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1()
      /Users/inanc/grafana/xk6-browser2/common/frame.go:288 +0x1a6

Goroutine 894 (running) created at:
  github.com/grafana/xk6-browser/common.(*FrameSession).initEvents()
      /Users/inanc/grafana/xk6-browser2/common/frame_session.go:206 +0x324
  github.com/grafana/xk6-browser/common.NewFrameSession()
      /Users/inanc/grafana/xk6-browser2/common/frame_session.go:132 +0xc8b
  github.com/grafana/xk6-browser/common.NewPage()
      /Users/inanc/grafana/xk6-browser2/common/page.go:117 +0xb0f
  github.com/grafana/xk6-browser/common.(*Browser).onAttachedToTarget()
      /Users/inanc/grafana/xk6-browser2/common/browser.go:244 +0x14e4
  github.com/grafana/xk6-browser/common.(*Browser).initEvents.func1·dwrap·4()
      /Users/inanc/grafana/xk6-browser2/common/browser.go:166 +0x47
==================
==================
WARNING: DATA RACE
Read at 0x00c0011b7118 by goroutine 429:
  github.com/grafana/xk6-browser/common.(*FrameManager).NavigateFrame()
      /Users/inanc/grafana/xk6-browser2/common/frame_manager.go:477 +0xb84
  github.com/grafana/xk6-browser/common.(*Frame).Goto()
      /Users/inanc/grafana/xk6-browser2/common/frame.go:721 +0x6c
  github.com/grafana/xk6-browser/common.(*Page).Goto()
      /Users/inanc/grafana/xk6-browser2/common/page.go:462 +0x1b2
  github.com/grafana/xk6-browser/tests.TestPageGoto()
      /Users/inanc/grafana/xk6-browser2/tests/page_test.go:41 +0x1d2
  testing.tRunner()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1306 +0x47

Previous write at 0x00c0011b7118 by goroutine 768:
  github.com/grafana/xk6-browser/common.(*NetworkManager).onResponseReceived()
      /Users/inanc/grafana/xk6-browser2/common/network_manager.go:404 +0x10a
  github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents()
      /Users/inanc/grafana/xk6-browser2/common/network_manager.go:281 +0x20e
  github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents.func1()
      /Users/inanc/grafana/xk6-browser2/common/network_manager.go:256 +0x3e

Goroutine 429 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1306 +0x726
  testing.runTests.func1()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1598 +0x99
  testing.tRunner()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1259 +0x22f
  testing.runTests()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1596 +0x7ca
  testing.(*M).Run()
      /usr/local/Cellar/go/1.17.3/libexec/src/testing/testing.go:1504 +0x9d1
  main.main()
      _testmain.go:103 +0x22b

Goroutine 768 (running) created at:
  github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents()
      /Users/inanc/grafana/xk6-browser2/common/network_manager.go:255 +0x2a4
  github.com/grafana/xk6-browser/common.NewNetworkManager()
      /Users/inanc/grafana/xk6-browser2/common/network_manager.go:93 +0x3f7
  github.com/grafana/xk6-browser/common.NewFrameSession()
      /Users/inanc/grafana/xk6-browser2/common/frame_session.go:119 +0x857
  github.com/grafana/xk6-browser/common.NewPage()
      /Users/inanc/grafana/xk6-browser2/common/page.go:117 +0xb0f
  github.com/grafana/xk6-browser/common.(*Browser).onAttachedToTarget()
      /Users/inanc/grafana/xk6-browser2/common/browser.go:244 +0x14e4
  github.com/grafana/xk6-browser/common.(*Browser).initEvents.func1·dwrap·4()
      /Users/inanc/grafana/xk6-browser2/common/browser.go:166 +0x47
==================
904: running [Created by common.(*FrameSession).initEvents @ frame_session.go:206] Race write @ 0xc0002af4f8
    common frame_manager.go:195 (*FrameManager).frameNavigated()
    common frame_session.go:593 (*FrameSession).onFrameNavigated()
    common frame_session.go:230 (*FrameSession).initEvents.func1()
631: finished [Created by common.(*Frame).startNetworkIdleTimer @ frame.go:283] Race read @ 0xc0002af4f8
    common frame.go:242         (*Frame).recalculateLifecycle()
    common frame_manager.go:149 (*FrameManager).frameLifecycleEvent()
    common frame.go:288         (*Frame).startNetworkIdleTimer.func1()
ser/common/event_emitter.go:120 +0x231

28: select [Created by common.(*Browser).initEvents @ browser.go:158]
    common   browser.go:160                (*Browser).initEvents.func1()
1: runnable [Created by common.NewBaseEventEmitter @ event_emitter.go:120]
    common   event_emitter.go:179          (*BaseEventEmitter).emit.func3()
    common   event_emitter.go:148          (*BaseEventEmitter).sync.func1()
    common   event_emitter.go:135          (*BaseEventEmitter).syncAll(*BaseEventEmitter(#188), Context{#4, #262})
1: chan receive [Created by common.NewConnection @ connection.go:147]
    common   event_emitter.go:153          (*BaseEventEmitter).sync(*BaseEventEmitter(#387), func(#625))
    common   event_emitter.go:178          (*BaseEventEmitter).emit(*BaseEventEmitter(#387), string(#638, len=25), interface{}{#1, #637})
    common   connection.go:336             (*Connection).recvLoop(*Connection(#387))
26: select [Created by common.NewConnection @ connection.go:147]
    common   connection.go:216             (*Connection).handleIOError(*, {#3, #5})
    common   connection.go:258             (*Connection).recvLoop(*)
62: select [Created by common.(*NetworkManager).initEvents @ network_manager.go:255]
    common   network_manager.go:262        (*NetworkManager).handleEvents(*, *)
    common   network_manager.go:256        (*NetworkManager).initEvents.func1()
1: runnable [Created by chromium.(*Allocator).Allocate @ allocator.go:229]
    syscall  syscall.go:54                 ByteSliceFromString(...)
    syscall  syscall.go:69                 BytePtrFromString(...)
    syscall  zsyscall_darwin_amd64.go:1799 unlinkat(824701370368, string(#261, len=12), 824658345984)
    unix     at_darwin.go:13               Unlinkat(...)
    os       removeall_at.go:155           removeAllFrom(*File(#507), string(#261, len=7))
    os       removeall_at.go:122           removeAllFrom(*File(#584), string(#635, len=32))
    os       removeall_at.go:122           removeAllFrom(*File(#480), string(#129, len=39381056))
    os       removeall_at.go:49            removeAll(string(#128, len=81))
    os       path.go:67                    RemoveAll(...)
    chromium allocator.go:234              (*Allocator).Allocate.func2()
1: runnable [Created by common.(*BaseEventEmitter).emit.func2 @ event_emitter.go:172]
    common   event_emitter.go:172          (*BaseEventEmitter).emit.func2·dwrap·23()
    runtime  asm_amd64.s:1581              goexit()
400: select [Created by common.NewBaseEventEmitter @ event_emitter.go:120]
    common   event_emitter.go:130          (*BaseEventEmitter).syncAll(*, {#4, *})
27: select [Created by common.NewConnection @ connection.go:148]
    common   connection.go:409             (*Connection).sendLoop(*)
62: select [Created by common.(*FrameSession).initEvents @ frame_session.go:206]
    common   frame_session.go:213          (*FrameSession).initEvents.func1()
41: select [Created by common.NewSession @ session.go:70]
    common   session.go:98                 (*Session).readLoop(*)
26: chan receive [Created by common.NewBrowserProcess @ browser_process.go:63]
    common   browser_process.go:66         NewBrowserProcess.func1()
1: chan send [Created by common.createWaitForEventHandler @ helpers.go:191]
    common   helpers.go:200                createWaitForEventHandler.func1()
FAIL    github.com/grafana/xk6-browser/tests    41.719s
inancgumus commented 11 months ago

141 fixed this.