go-telegram / bot

Telegram Bot API Go framework
MIT License
502 stars 46 forks source link

possible webhook data race in current tests #79

Closed egor-denysenko closed 2 months ago

egor-denysenko commented 2 months ago

Hi, i was checking out the tests and currently there is a data race in the webhook functionality of the bot, if it's needed i can check out the tests and propose a fix for the data race.

Steps to reproduce:

Output log for failing test:

=== RUN   TestBot_StartWebhook
==================
WARNING: DATA RACE
Read at 0x00c00021e1af by goroutine 24:
  github.com/go-telegram/bot.TestBot_StartWebhook()
      ./bot_test.go:203 +0x688
  testing.tRunner()
      ./src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      ./src/testing/testing.go:1742 +0x44

Previous write at 0x00c00021e1af by goroutine 33:
  github.com/go-telegram/bot.TestBot_StartWebhook.func1()
      ./bot_test.go:181 +0x8e
  github.com/go-telegram/bot.(*Bot).ProcessUpdate.func1()
      ./process_update.go:25 +0xaf
  runtime.deferreturn()
      ./src/runtime/panic.go:602 +0x5d
  github.com/go-telegram/bot.(*Bot).waitUpdates()
      ./wait_updates.go:17 +0xd2
  github.com/go-telegram/bot.(*Bot).StartWebhook.gowrap1()
      ./bot.go:106 +0x5d

Goroutine 24 (running) created at:
  testing.(*T).Run()
      ./src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      ./src/testing/testing.go:2161 +0x85
  testing.tRunner()
      ./src/testing/testing.go:1689 +0x21e
  testing.runTests()
      ./src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      ./src/testing/testing.go:2027 +0xf17
  main.main()
      _testmain.go:79 +0x2bd

Goroutine 33 (finished) created at:
  github.com/go-telegram/bot.(*Bot).StartWebhook()
      ./bot.go:106 +0x150
  github.com/go-telegram/bot.TestBot_StartWebhook.gowrap2()
      ./bot_test.go:187 +0x4f
==================
    testing.go:1398: race detected during execution of test
--- FAIL: TestBot_StartWebhook (0.22s)
=== RUN   TestBot_Start
==================
WARNING: DATA RACE
Read at 0x00c00030817f by goroutine 36:
  github.com/go-telegram/bot.TestBot_Start()
      ./bot_test.go:238 +0x708
  testing.tRunner()
      ./src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      ./src/testing/testing.go:1742 +0x44

Previous write at 0x00c00030817f by goroutine 45:
  github.com/go-telegram/bot.TestBot_Start.func1()
      ./bot_test.go:225 +0x10e
  github.com/go-telegram/bot.(*Bot).ProcessUpdate.func1()
      ./process_update.go:25 +0xaf
  runtime.deferreturn()
      ./src/runtime/panic.go:602 +0x5d
  github.com/go-telegram/bot.(*Bot).waitUpdates()
      ./wait_updates.go:17 +0xd2
  github.com/go-telegram/bot.(*Bot).Start.gowrap1()
      ./bot.go:116 +0x5d

Goroutine 36 (running) created at:
  testing.(*T).Run()
      ./src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      ./src/testing/testing.go:2161 +0x85
  testing.tRunner()
      ./src/testing/testing.go:1689 +0x21e
  testing.runTests()
      ./src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      ./src/testing/testing.go:2027 +0xf17
  main.main()
      _testmain.go:79 +0x2bd

Goroutine 45 (finished) created at:
  github.com/go-telegram/bot.(*Bot).Start()
      ./bot.go:116 +0x150
  github.com/go-telegram/bot.TestBot_Start.gowrap2()
      ./bot_test.go:230 +0x4f
==================
    testing.go:1398: race detected during execution of test
--- FAIL: TestBot_Start (0.20s)
negasus commented 2 months ago

Fixed, thanks