Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race for empty strings #3477

Closed
SupunS opened this issue Jul 18, 2024 · 3 comments · Fixed by #3481
Closed

Data race for empty strings #3477

SupunS opened this issue Jul 18, 2024 · 3 comments · Fixed by #3481
Assignees
Labels
Bug Something isn't working

Comments

@SupunS
Copy link
Member

SupunS commented Jul 18, 2024

Current Behavior

Likely to be from StringValue.

2024-07-18T14:20:51.5191297Z ==================
2024-07-18T14:20:51.5191885Z WARNING: DATA RACE
2024-07-18T14:20:51.5192631Z Write at 0x00c0005ed3f0 by goroutine 1264:
2024-07-18T14:20:51.5194184Z   github.com/rivo/uniseg.(*Graphemes).Reset()
2024-07-18T14:20:51.5195780Z       /home/runner/go/pkg/mod/github.com/rivo/uniseg@v0.4.4/grapheme.go:149 +0x2eb
2024-07-18T14:20:51.5197215Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).prepareGraphemes()
2024-07-18T14:20:51.5198736Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1101 +0x2a9
2024-07-18T14:20:51.5200232Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).indexOf()
2024-07-18T14:20:51.5201826Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1925 +0x222
2024-07-18T14:20:51.5203389Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).count()
2024-07-18T14:20:51.5205015Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1999 +0x2ea
2024-07-18T14:20:51.5206414Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).Count()
2024-07-18T14:20:51.5208373Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1983 +0xec
2024-07-18T14:20:51.5209842Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).GetMember.func5()
2024-07-18T14:20:51.5211422Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1425 +0xbb
2024-07-18T14:20:51.5212955Z   github.com/onflow/cadence/runtime/interpreter.(*HostFunctionValue).invoke()
2024-07-18T14:20:51.5214593Z       /home/runner/work/cadence/cadence/runtime/interpreter/value_function.go:258 +0xf4
2024-07-18T14:20:51.5216053Z   github.com/onflow/cadence/runtime/interpreter.BoundFunctionValue.invoke()
2024-07-18T14:20:51.5217785Z       /home/runner/work/cadence/cadence/runtime/interpreter/value_function.go:426 +0x2f4
2024-07-18T14:20:51.5219295Z   github.com/onflow/cadence/runtime/interpreter.(*BoundFunctionValue).invoke()
2024-07-18T14:20:51.5220453Z       <autogenerated>:1 +0xfd
2024-07-18T14:20:51.5221732Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeFunctionValue()
2024-07-18T14:20:51.5223536Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:125 +0x21c
2024-07-18T14:20:51.5225468Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).visitInvocationExpressionWithImplicitArgument()
2024-07-18T14:20:51.5227730Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_expression.go:1209 +0xdd8
2024-07-18T14:20:51.5229941Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).VisitInvocationExpression()
2024-07-18T14:20:51.5232012Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_expression.go:1123 +0x89
2024-07-18T14:20:51.5234220Z   github.com/onflow/cadence/runtime/ast.AcceptExpression[go.shape.03355aee8013d1c9a3e0834fea44bfa51a92741bebbb78c284ee9a1065f5d5bc]()
2024-07-18T14:20:51.5236222Z       /home/runner/work/cadence/cadence/runtime/ast/visitor.go:241 +0x3f5
2024-07-18T14:20:51.5237663Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).evalExpression()
2024-07-18T14:20:51.5239457Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_expression.go:418 +0x9d
2024-07-18T14:20:51.5241080Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).VisitReturnStatement()
2024-07-18T14:20:51.5242969Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_statement.go:78 +0xe5
2024-07-18T14:20:51.5245241Z   github.com/onflow/cadence/runtime/ast.AcceptStatement[go.shape.interface { github.com/onflow/cadence/runtime/interpreter.isStatementResult() }]()
2024-07-18T14:20:51.5247294Z       /home/runner/work/cadence/cadence/runtime/ast/visitor.go:118 +0x395
2024-07-18T14:20:51.5248712Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).evalStatement()
2024-07-18T14:20:51.5250536Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_statement.go:56 +0x34f
2024-07-18T14:20:51.5252261Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).visitStatements()
2024-07-18T14:20:51.5254227Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_statement.go:62 +0x10b
2024-07-18T14:20:51.5256119Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeInterpretedFunctionActivated.func2()
2024-07-18T14:20:51.5258307Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:182 +0x6f
2024-07-18T14:20:51.5259991Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).visitFunctionBody()
2024-07-18T14:20:51.5261680Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:779 +0x3f7
2024-07-18T14:20:51.5263478Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeInterpretedFunctionActivated()
2024-07-18T14:20:51.5265498Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:178 +0x5c8
2024-07-18T14:20:51.5267182Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeInterpretedFunction()
2024-07-18T14:20:51.5269145Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:156 +0x5d2
2024-07-18T14:20:51.5271228Z   github.com/onflow/cadence/runtime/interpreter.(*InterpretedFunctionValue).invoke()
2024-07-18T14:20:51.5272819Z       /home/runner/work/cadence/cadence/runtime/interpreter/value_function.go:125 +0xc4
2024-07-18T14:20:51.5274412Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).InvokeExternally()
2024-07-18T14:20:51.5275981Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:465 +0x79c
2024-07-18T14:20:51.5277436Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeVariable()
2024-07-18T14:20:51.5279083Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:395 +0x3af
2024-07-18T14:20:51.5280054Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).Invoke()
2024-07-18T14:20:51.5280982Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:476 +0x1cd
2024-07-18T14:20:51.5282066Z   github.com/onflow/cadence/runtime/tests/interpreter_test.TestInterpretStringCount.func1.1()
2024-07-18T14:20:51.5283177Z       /home/runner/work/cadence/cadence/runtime/tests/interpreter/string_test.go:926 +0x124
2024-07-18T14:20:51.5283934Z   testing.tRunner()
2024-07-18T14:20:51.5284575Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1689 +0x21e
2024-07-18T14:20:51.5285166Z   testing.(*T).Run.gowrap1()
2024-07-18T14:20:51.5286081Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1742 +0x44
2024-07-18T14:20:51.5286531Z 
2024-07-18T14:20:51.5286768Z Previous write at 0x00c0005ed3f0 by goroutine 1275:
2024-07-18T14:20:51.5287330Z   github.com/rivo/uniseg.(*Graphemes).Reset()
2024-07-18T14:20:51.5288180Z       /home/runner/go/pkg/mod/github.com/rivo/uniseg@v0.4.4/grapheme.go:149 +0x2eb
2024-07-18T14:20:51.5289087Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).prepareGraphemes()
2024-07-18T14:20:51.5290020Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1101 +0x2a9
2024-07-18T14:20:51.5290921Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).indexOf()
2024-07-18T14:20:51.5291838Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1925 +0x222
2024-07-18T14:20:51.5292644Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).count()
2024-07-18T14:20:51.5293598Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1999 +0x2ea
2024-07-18T14:20:51.5294412Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).Count()
2024-07-18T14:20:51.5295252Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1983 +0xec
2024-07-18T14:20:51.5296200Z   github.com/onflow/cadence/runtime/interpreter.(*StringValue).GetMember.func5()
2024-07-18T14:20:51.5297133Z       /home/runner/work/cadence/cadence/runtime/interpreter/value.go:1425 +0xbb
2024-07-18T14:20:51.5298031Z   github.com/onflow/cadence/runtime/interpreter.(*HostFunctionValue).invoke()
2024-07-18T14:20:51.5299019Z       /home/runner/work/cadence/cadence/runtime/interpreter/value_function.go:258 +0xf4
2024-07-18T14:20:51.5299936Z   github.com/onflow/cadence/runtime/interpreter.BoundFunctionValue.invoke()
2024-07-18T14:20:51.5300952Z       /home/runner/work/cadence/cadence/runtime/interpreter/value_function.go:426 +0x2f4
2024-07-18T14:20:51.5301851Z   github.com/onflow/cadence/runtime/interpreter.(*BoundFunctionValue).invoke()
2024-07-18T14:20:51.5302515Z       <autogenerated>:1 +0xfd
2024-07-18T14:20:51.5303284Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeFunctionValue()
2024-07-18T14:20:51.5304368Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:125 +0x21c
2024-07-18T14:20:51.5305475Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).visitInvocationExpressionWithImplicitArgument()
2024-07-18T14:20:51.5306772Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_expression.go:1209 +0xdd8
2024-07-18T14:20:51.5307797Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).VisitInvocationExpression()
2024-07-18T14:20:51.5309047Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_expression.go:1123 +0x89
2024-07-18T14:20:51.5310615Z   github.com/onflow/cadence/runtime/ast.AcceptExpression[go.shape.03355aee8013d1c9a3e0834fea44bfa51a92741bebbb78c284ee9a1065f5d5bc]()
2024-07-18T14:20:51.5311796Z       /home/runner/work/cadence/cadence/runtime/ast/visitor.go:241 +0x3f5
2024-07-18T14:20:51.5312700Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).evalExpression()
2024-07-18T14:20:51.5313714Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_expression.go:418 +0x9d
2024-07-18T14:20:51.5314714Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).VisitReturnStatement()
2024-07-18T14:20:51.5315830Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_statement.go:78 +0xe5
2024-07-18T14:20:51.5317131Z   github.com/onflow/cadence/runtime/ast.AcceptStatement[go.shape.interface { github.com/onflow/cadence/runtime/interpreter.isStatementResult() }]()
2024-07-18T14:20:51.5318350Z       /home/runner/work/cadence/cadence/runtime/ast/visitor.go:118 +0x395
2024-07-18T14:20:51.5319369Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).evalStatement()
2024-07-18T14:20:51.5320372Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_statement.go:56 +0x34f
2024-07-18T14:20:51.5321494Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).visitStatements()
2024-07-18T14:20:51.5322610Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_statement.go:62 +0x10b
2024-07-18T14:20:51.5323725Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeInterpretedFunctionActivated.func2()
2024-07-18T14:20:51.5324894Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:182 +0x6f
2024-07-18T14:20:51.5325948Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).visitFunctionBody()
2024-07-18T14:20:51.5326902Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:779 +0x3f7
2024-07-18T14:20:51.5327912Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeInterpretedFunctionActivated()
2024-07-18T14:20:51.5329143Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:178 +0x5c8
2024-07-18T14:20:51.5330158Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeInterpretedFunction()
2024-07-18T14:20:51.5331335Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter_invocation.go:156 +0x5d2
2024-07-18T14:20:51.5332321Z   github.com/onflow/cadence/runtime/interpreter.(*InterpretedFunctionValue).invoke()
2024-07-18T14:20:51.5333331Z       /home/runner/work/cadence/cadence/runtime/interpreter/value_function.go:125 +0xc4
2024-07-18T14:20:51.5334291Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).InvokeExternally()
2024-07-18T14:20:51.5335300Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:465 +0x79c
2024-07-18T14:20:51.5336199Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).invokeVariable()
2024-07-18T14:20:51.5337245Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:395 +0x3af
2024-07-18T14:20:51.5338097Z   github.com/onflow/cadence/runtime/interpreter.(*Interpreter).Invoke()
2024-07-18T14:20:51.5339003Z       /home/runner/work/cadence/cadence/runtime/interpreter/interpreter.go:476 +0x1cd
2024-07-18T14:20:51.5340054Z   github.com/onflow/cadence/runtime/tests/interpreter_test.TestInterpretStringCount.func1.1()
2024-07-18T14:20:51.5341139Z       /home/runner/work/cadence/cadence/runtime/tests/interpreter/string_test.go:926 +0x124
2024-07-18T14:20:51.5341846Z   testing.tRunner()
2024-07-18T14:20:51.5342540Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1689 +0x21e
2024-07-18T14:20:51.5343158Z   testing.(*T).Run.gowrap1()
2024-07-18T14:20:51.5343775Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1742 +0x44
2024-07-18T14:20:51.5345316Z 
2024-07-18T14:20:51.5345484Z Goroutine 1264 (running) created at:
2024-07-18T14:20:51.5345950Z   testing.(*T).Run()
2024-07-18T14:20:51.5346629Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1742 +0x825
2024-07-18T14:20:51.5347546Z   github.com/onflow/cadence/runtime/tests/interpreter_test.TestInterpretStringCount.func1()
2024-07-18T14:20:51.5348622Z       /home/runner/work/cadence/cadence/runtime/tests/interpreter/string_test.go:909 +0x197
2024-07-18T14:20:51.5349893Z   github.com/onflow/cadence/runtime/tests/interpreter_test.TestInterpretStringCount()
2024-07-18T14:20:51.5351121Z       /home/runner/work/cadence/cadence/runtime/tests/interpreter/string_test.go:936 +0x154
2024-07-18T14:20:51.5351818Z   testing.tRunner()
2024-07-18T14:20:51.5352572Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1689 +0x21e
2024-07-18T14:20:51.5353193Z   testing.(*T).Run.gowrap1()
2024-07-18T14:20:51.5353802Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1742 +0x44
2024-07-18T14:20:51.5354319Z 
2024-07-18T14:20:51.5354486Z Goroutine 1275 (finished) created at:
2024-07-18T14:20:51.5354953Z   testing.(*T).Run()
2024-07-18T14:20:51.5355565Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1742 +0x825
2024-07-18T14:20:51.5356548Z   github.com/onflow/cadence/runtime/tests/interpreter_test.TestInterpretStringCount.func1()
2024-07-18T14:20:51.5357792Z       /home/runner/work/cadence/cadence/runtime/tests/interpreter/string_test.go:909 +0x197
2024-07-18T14:20:51.5358746Z   github.com/onflow/cadence/runtime/tests/interpreter_test.TestInterpretStringCount()
2024-07-18T14:20:51.5359909Z       /home/runner/work/cadence/cadence/runtime/tests/interpreter/string_test.go:936 +0x154
2024-07-18T14:20:51.5360620Z   testing.tRunner()
2024-07-18T14:20:51.5361327Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1689 +0x21e
2024-07-18T14:20:51.5361942Z   testing.(*T).Run.gowrap1()
2024-07-18T14:20:51.5362564Z       /opt/hostedtoolcache/go/1.22.5/x64/src/testing/testing.go:1742 +0x44
2024-07-18T14:20:51.5363234Z ==================

Complete Log

Expected Behavior

No data-races should be present

Steps To Reproduce

see above.

Environment

- Cadence version: master
- Network: N/A
@SupunS SupunS added the Bug Something isn't working label Jul 18, 2024
@turbolent
Copy link
Member

Seems really odd: I can't see how the string values are used concurrently in the tests 🤔

@turbolent
Copy link
Member

turbolent commented Jul 19, 2024

Took me quite a while to realize, but: the culprit are not the tests, it is that some of the test cases work with / result in empty strings, which returns the EmptyString global, and its graphemes are mutated across goroutines.

It would be good to keep empty strings case optimized, but avoid the mutation of it or parts of it (the graphemes iterator)

@turbolent turbolent changed the title Race condition detected during CI Data race for empty strings Jul 19, 2024
@SupunS
Copy link
Member Author

SupunS commented Jul 19, 2024

aha good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
2 participants