bruth / django-tracking2

django-tracking2 tracks the length of time visitors and registered users spend on your site. Although this will work for websites, this is more applicable to web _applications_ with registered users. This does not replace (nor intend) to replace client-side analytics which is great for understanding aggregate flow of page views.
BSD 2-Clause "Simplified" License
205 stars 67 forks source link

Race condition #52

Closed mjschultz closed 9 years ago

mjschultz commented 9 years ago

We have a system that automatically logs users out after a period of inactivity. Every so often we get an IntegrityError thrown claiming that the session_key already exists in the database. This should fix it.

I say should because race conditions are hard to test for. I thought I had a good test but it passed. I believe what is happening is the .save() is going through the UPDATE version, two threads get the response that nothing was updated, then both attempt to INSERT. One succeeds, the other fails with an IntegrityError. These changes catch the IntegrityError and simply return the winning Visitor object (which should make the resulting Pageview have a good reference).

Since the sessions time out at the same instance the objects should be identical (okay perhaps a few microseconds apart on some of the times, whatever).

mjschultz commented 9 years ago

Should I rebase the two bad commits away or leave them?

bruth commented 9 years ago

Please rebase. Thanks.

mjschultz commented 9 years ago

Done.

bruth commented 9 years ago

Thanks!

bruth commented 9 years ago

Released: https://pypi.python.org/pypi/django-tracking2/0.2.4

mjschultz commented 9 years ago

Thanks for the release!