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

Race condition in getQuery #26

Closed
sgoldenb opened this issue Dec 19, 2019 · 4 comments
Closed

Race condition in getQuery #26

sgoldenb opened this issue Dec 19, 2019 · 4 comments
Labels

Comments

@sgoldenb
Copy link

Hi,
i have a project in which multiple go routines parse xml files in parallel.
Today i got the following crash:

fatal error: concurrent map read and map write
goroutine 509 [running]:
runtime.throw(0xaf97d6, 0x21)
/usr/lib/go-1.13/src/runtime/panic.go:774 +0x72 fp=0xc004fb9678 sp=0xc004fb9648 pc=0x446712
runtime.mapaccess2(0xa20ec0, 0xc000299a10, 0xc004fb96e8, 0xc0002afef8, 0xc0002f68d8)
/usr/lib/go-1.13/src/runtime/map.go:470 +0x278 fp=0xc004fb96c0 sp=0xc004fb9678 pc=0x4255c8
github.com/golang/groupcache/lru.(*Cache).Get(0xc003a7b640, 0x9fa140, 0xc004fb9740, 0xc0002f68d8, 0xc0034b6200, 0x390000c004774720)
/root/go/pkg/mod/github.com/golang/groupcache@v0.0.0-20191027212112-611e8accdfc9/lru/lru.go:78 +0x68 fp=0xc004fb9708 sp=0xc004fb96c0 pc=0x8d88a8
github.com/antchfx/xmlquery.getQuery(0xc0000248e0, 0x20, 0x11d3ef0, 0x0, 0xc0002afee0)
/root/go/pkg/mod/github.com/antchfx/xmlquery@v1.2.1/cache.go:30 +0xbd fp=0xc004fb9760 sp=0xc004fb9708 pc=0x91359d
github.com/antchfx/xmlquery.Query(0xc00017cc00, 0xc0000248e0, 0x20, 0xc0034b6200, 0x0, 0xc0000248a0)
/root/go/pkg/mod/github.com/antchfx/xmlquery@v1.2.1/query.go:103 +0x39 fp=0xc004fb9798 sp=0xc004fb9760 pc=0x9162e9
github.com/antchfx/xmlquery.FindOne(...)
/root/go/pkg/mod/github.com/antchfx/xmlquery@v1.2.1/query.go:83

In findOne there is a package variable for the not thread save groupace/lru and since i use xmlqery concurrently the whole thing can crash here.

It is possible to disable the cache but i am not sure how much this would impact performance.

I guess that adding a mutex here would not impact performance as much as disabling the cache completely.

Should i write a pr for this?

Best regards
Sebastian

@zhengchun
Copy link
Contributor

It is an open project, You can submit a PR anytime.

@zhengchun
Copy link
Contributor

htmlquery package have the same bug: antchfx/htmlquery#19

@vtolstov
Copy link

I'm take this, as i already have fix internally.

zhengchun added a commit that referenced this issue Dec 23, 2019
@zhengchun zhengchun added the bug label Dec 25, 2019
@zhengchun
Copy link
Contributor

Closed. It fixed in Release 1.2.2.

zhengchun added a commit that referenced this issue Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants