lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
138 stars 13 forks source link

Race Condition in ping/pong handler #11

Closed Kethsar closed 6 years ago

Kethsar commented 6 years ago

After making a simple client and building with -race, a data race was found rather fast involving the ping/pong handling code.

==================
WARNING: DATA RACE
Read at 0x00c0420f2090 by goroutine 14:
  github.com/lrstanley/girc.(*Client).pingLoop()
      F:/goenv/src/github.com/lrstanley/girc/conn.go:546 +0x5b0

Previous write at 0x00c0420f2090 by goroutine 53:
  github.com/lrstanley/girc.handlePONG()
      F:/goenv/src/github.com/lrstanley/girc/builtin.go:116 +0x91
  github.com/lrstanley/girc.HandlerFunc.Execute()
      F:/goenv/src/github.com/lrstanley/girc/handler.go:67 +0x77
  github.com/lrstanley/girc.(*Caller).exec.func1()
      F:/goenv/src/github.com/lrstanley/girc/handler.go:231 +0x476

Goroutine 14 (running) created at:
  github.com/lrstanley/girc.(*Client).internalConnect()
      F:/goenv/src/github.com/lrstanley/girc/conn.go:284 +0x3b7
  github.com/lrstanley/girc.(*Client).Connect()
      F:/goenv/src/github.com/lrstanley/girc/conn.go:184 +0x4c
  main.main()
      F:/goenv/src/github.com/R-a-dio/valkyrie/cmd/hanyuu/main.go:33 +0x195

Goroutine 53 (finished) created at:
  github.com/lrstanley/girc.(*Caller).exec()
      F:/goenv/src/github.com/lrstanley/girc/handler.go:209 +0x276
  github.com/lrstanley/girc.(*Client).RunHandlers()
      F:/goenv/src/github.com/lrstanley/girc/handler.go:45 +0x40a
  github.com/lrstanley/girc.(*Client).execLoop()
      F:/goenv/src/github.com/lrstanley/girc/client.go:345 +0x18a
==================
lrstanley commented 6 years ago

Sorry I didn't notice this sooner, Github didn't send me a notification. Should be fixed in e46d210b5d866a16737d960f57fa9f0c50b9f86a, looks like my tests didn't catch that, even with -race enabled when running tests. Will have to add some more test cases when I get a chance.