mmcdole / gofeed

Parse RSS, Atom and JSON feeds in Go
MIT License
2.56k stars 208 forks source link

Make Parser thread-safe (use new goxpp's base:xml state) #202

Closed cristoper closed 1 year ago

cristoper commented 1 year ago

This PR changes the xml:base implementation to use state maintained by the goxxp parser instead of using a shared urlStack. This allows Parser to be safely used concurrently.

Depends on: https://github.com/mmcdole/goxpp/pull/9

With the url stack state maintined by goxpp, all of the methods of the old XMLBase type become package-level helper functions of shared (these are still in internal/shared/xmlbase.go though they could be moved to parseutils.go).

This is an alternative to #201 to fix #160 and #159.

To test: go test -race

Note that this PR does not update go.mod. I guess that needs to be done after a release of goxpp if the above PR is accepted. For development purposes I have this line in go.mod pointing to a local copy of goxpp:

replace github.com/mmcdole/goxpp => ../goxpp/

mmcdole commented 1 year ago

@cristoper - I accept the PR.

I've cut a new v1.1.0 release of goxpp, if you want to update your go.mod file. Once you do, I'll merge this in.

cristoper commented 1 year ago

Thanks! This should be good to merge now.