Skip to content

Conversation

bshafiee
Copy link

@bshafiee bshafiee commented Apr 1, 2019

When multiple IndexWriter instances call Flush concurrently, they hit race or index out of range for sortTmp since it's getting modified from multiple go routines.
example:

goroutine 59 [running]:
github.com/meerkat/vendor/github.com/google/codesearch/index.sortPost(0xc023ab0000, 0x32f2, 0x800000)
	/Users/behrooz/go/src/github.com/meerkat/vendor/github.com/google/codesearch/index/write.go:648 +0x298
github.com/meerkat/vendor/github.com/google/codesearch/index.(*IndexWriter).mergePost(0xc0000d62c0, 0xc001e8e300)
	/Users/behrooz/go/src/github.com/meerkat/vendor/github.com/google/codesearch/index/write.go:291 +0x13c
github.com/meerkat/vendor/github.com/google/codesearch/index.(*IndexWriter).Flush(0xc0000d62c0)
	/Users/behrooz/go/src/github.com/meerkat/vendor/github.com/google/codesearch/index/write.go:210 +0x1f1
github.com/meerkat/index.(*indexer).Index(0xc00011e000, 0x13a56e0, 0xc001fb4060, 0x0, 0x0)
	/Users/behrooz/go/src/github.com/meerkat/index/indexer.go:239 +0x429
main.main.func1(0xc0002c4280, 0xc001e4e6d0, 0xc00011c000, 0x30, 0x13a25a0, 0xc00011e000, 0xc00039b800)
	/Users/behrooz/go/src/github.com/meerkat/main.go:88 +0x206
created by main.main
	/Users/behrooz/go/src/github.com/meerkat/main.go:76 +0x334
panic: runtime error: index out of range

goroutine 181 [running]:
github.com/meerkat/vendor/github.com/google/codesearch/index.sortPost(0xc01fab0000, 0x3b65, 0x800000)
	/Users/behrooz/go/src/github.com/meerkat/vendor/github.com/google/codesearch/index/write.go:628 +0x29f
github.com/meerkat/vendor/github.com/google/codesearch/index.(*IndexWriter).mergePost(0xc0011d2000, 0xc0000a6240)
	/Users/behrooz/go/src/github.com/meerkat/vendor/github.com/google/codesearch/index/write.go:291 +0x13c
github.com/meerkat/vendor/github.com/google/codesearch/index.(*IndexWriter).Flush(0xc0011d2000)
	/Users/behrooz/go/src/github.com/meerkat/vendor/github.com/google/codesearch/index/write.go:210 +0x1f1
github.com/meerkat/index.(*indexer).Index(0xc00011e000, 0x13a56e0, 0xc0003a7ae0, 0x0, 0x0)
	/Users/behrooz/go/src/github.com/meerkat/index/indexer.go:239 +0x429
main.main.func1(0xc0002c4280, 0xc001e4e6d0, 0xc00011c000, 0x30, 0x13a25a0, 0xc00011e000, 0xc00039b500)
	/Users/behrooz/go/src/github.com/meerkat/main.go:88 +0x206
created by main.main
	/Users/behrooz/go/src/github.com/meerkat/main.go:76 +0x334

This fix simply moves global unprotected vars to local func scope. We could alternatively include them in IndexWriter struct too.

… the fix simply moves global unprotected vars to local func scope
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@bshafiee
Copy link
Author

bshafiee commented Apr 1, 2019

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@bshafiee
Copy link
Author

bshafiee commented Apr 1, 2019

@dgryski @rsc would you mind taking a look pretty please? it's a tiny PR.

@dgryski
Copy link
Contributor

dgryski commented Apr 1, 2019

LGTM. However, I don't have a commit bit for this repo.

@bshafiee
Copy link
Author

bshafiee commented Oct 1, 2021

ping @rsc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants