Skip to content

fakesqldb: Guard query log usage with lock#12813

Merged
dbussink merged 3 commits intovitessio:mainfrom
planetscale:dbussink/fix-race-fakesqldb
Apr 3, 2023
Merged

fakesqldb: Guard query log usage with lock#12813
dbussink merged 3 commits intovitessio:mainfrom
planetscale:dbussink/fix-race-fakesqldb

Conversation

@dbussink
Copy link
Member

@dbussink dbussink commented Apr 3, 2023

This lock is used around adding to the query log, but it means we also need to use the lock when reading from it or when resetting it.

We've seen this cause race test failures which look like this:

$ go test -trimpath -race -v -count=1000 ./go/vt/vttablet/tabletserver -run TestReserveExecute_WithTx
=== RUN   TestReserveExecute_WithTx
E0403 15:54:57.850444    4408 server.go:418] Query not found: set @@session.sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
E0403 15:54:57.854239    4408 server.go:418] Query not found: show full tables like '\_vt\_%'
==================
WARNING: DATA RACE
Write at 0x00c000556460 by goroutine 363:
  vitess.io/vitess/go/mysql/fakesqldb.(*DB).ResetQueryLog()
      vitess.io/vitess/go/mysql/fakesqldb/server.go:624 +0x1d8
  vitess.io/vitess/go/vt/vttablet/tabletserver.TestReserveExecute_WithTx()
      vitess.io/vitess/go/vt/vttablet/tabletserver/tabletserver_test.go:1899 +0x1cc
  testing.tRunner()
      testing/testing.go:1576 +0x180
  testing.(*T).Run.func1()
      testing/testing.go:1629 +0x40

Previous write at 0x00c000556460 by goroutine 414:
  vitess.io/vitess/go/mysql/fakesqldb.(*DB).HandleQuery()
      vitess.io/vitess/go/mysql/fakesqldb/server.go:361 +0x2d4
  vitess.io/vitess/go/mysql/fakesqldb.(*DB).ComQuery()
      vitess.io/vitess/go/mysql/fakesqldb/server.go:336 +0x68
  vitess.io/vitess/go/mysql.(*Conn).execQuery()
      vitess.io/vitess/go/mysql/conn.go:1359 +0x1a4
  vitess.io/vitess/go/mysql.(*Conn).handleComQuery()
      vitess.io/vitess/go/mysql/conn.go:1344 +0x364
  vitess.io/vitess/go/mysql.(*Conn).handleNextCommand()
      vitess.io/vitess/go/mysql/conn.go:910 +0x184
  vitess.io/vitess/go/mysql.(*Listener).handle()
      vitess.io/vitess/go/mysql/server.go:527 +0x1460
  vitess.io/vitess/go/mysql.(*Listener).Accept.func1()
      vitess.io/vitess/go/mysql/server.go:331 +0x1a0

Goroutine 363 (running) created at:
  testing.(*T).Run()
      testing/testing.go:1629 +0x5b4
  testing.runTests.func1()
      testing/testing.go:2036 +0x80
  testing.tRunner()
      testing/testing.go:1576 +0x180
  testing.runTests()
      testing/testing.go:2034 +0x6a8
  testing.(*M).Run()
      testing/testing.go:1906 +0x8e0
  main.main()
      _testmain.go:435 +0x2b8

Goroutine 414 (running) created at:
  vitess.io/vitess/go/mysql.(*Listener).Accept()
      vitess.io/vitess/go/mysql/server.go:322 +0x48
  vitess.io/vitess/go/mysql/fakesqldb.New.func1()
      vitess.io/vitess/go/mysql/fakesqldb/server.go:194 +0x74
==================
W0403 15:54:57.855201    4408 tabletserver.go:1557] Code: ABORTED
transaction 1680530097843343001: ended at 2023-04-03 15:54:57.855 CEST (release connection)
: Sql: "", BindVars: {}
    testing.go:1446: race detected during execution of test
--- FAIL: TestReserveExecute_WithTx (0.02s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

This lock is used around adding to the query log, but it means we also
need to use the lock when reading from it or when resetting it.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Apr 3, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.
  • If a test is added or modified, there should be a documentation on top of the test to explain what the expected behavior is what the test does.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow should be required, the maintainer team should be notified.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Apr 3, 2023
@frouioui frouioui removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Apr 3, 2023
dbussink added 2 commits April 3, 2023 17:22
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
We've been adding a lot of tests for the evalengine and we're bumping up
to the timeout.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink dbussink force-pushed the dbussink/fix-race-fakesqldb branch from f649611 to c143a9b Compare April 3, 2023 15:22
@dbussink dbussink merged commit aa87bc4 into vitessio:main Apr 3, 2023
@dbussink dbussink deleted the dbussink/fix-race-fakesqldb branch April 3, 2023 18:18
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Apr 3, 2023

I was unable to backport this Pull Request to the following branches: release-14.0, release-15.0, release-16.0.

timvaillancourt pushed a commit to slackhq/vitess that referenced this pull request Aug 20, 2024
* fakesqldb: Guard query log usage with lock

This lock is used around adding to the query log, but it means we also
need to use the lock when reading from it or when resetting it.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* grpcvtctldserver: Fix alias for loop reuse

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* unit_race: Increase runtime

We've been adding a lot of tests for the evalengine and we're bumping up
to the timeout.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

---------

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
timvaillancourt added a commit to slackhq/vitess that referenced this pull request Aug 20, 2024
…492)

* WIP

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* update all flags

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* update e2e flag test

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* 2 missing flags

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* rename Type()

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* empty commit to test ci

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* fakesqldb: Guard query log usage with lock (vitessio#12813)

* fakesqldb: Guard query log usage with lock

This lock is used around adding to the query log, but it means we also
need to use the lock when reading from it or when resetting it.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* grpcvtctldserver: Fix alias for loop reuse

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* unit_race: Increase runtime

We've been adding a lot of tests for the evalengine and we're bumping up
to the timeout.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

---------

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* remove t.Parallel() like upstream did

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

---------

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
makinje16 pushed a commit to slackhq/vitess that referenced this pull request Aug 28, 2024
…492)

* WIP

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* update all flags

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* update e2e flag test

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* 2 missing flags

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* rename Type()

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* empty commit to test ci

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* fakesqldb: Guard query log usage with lock (vitessio#12813)

* fakesqldb: Guard query log usage with lock

This lock is used around adding to the query log, but it means we also
need to use the lock when reading from it or when resetting it.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* grpcvtctldserver: Fix alias for loop reuse

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* unit_race: Increase runtime

We've been adding a lot of tests for the evalengine and we're bumping up
to the timeout.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

---------

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* remove t.Parallel() like upstream did

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

---------

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants