Closed raviteja-ms closed 7 years ago
I'll prioritize this next time I work on this lib.
Ok... Please resolve it ASAP. Thanks..!!
@kirsle Any update..??
Haven't had a chance to work on this module recently. I have an idea of how to resolve this issue, though, and that would also bring a useful new feature to the Go version: pluggable session managers.
In the Python version I added a pluggable session manager in PR #32. The main characteristics of this were:
self._users
(the old internal memory store for user data; in Go it's rs.users
) to instead use the getter/setter functions of the session manager. set_uservar example from PythonThis will centralize all reads and writes to user data into a small handful of functions in one place in the code. At that point it would be easy to use a mutex to ensure thread safety. And as a side effect it would bring the session manager feature from the Python version so that users can swap out the in-memory store with something backed by a database if they want.
It's mostly just a lot of busywork to apply the above fixes. I also did the work for the above for the JavaScript version (PR #137), but backed out on that because of JavaScript's heavy async nature not getting along well with how RiveScript manages user data.
In the mean time, consider using your own mutex at a level higher than where you call rs.Reply()
. RiveScript is intended to reply very quickly to messages so hopefully locking at that level in your program shouldn't incur too much of a performance hit.
I've opened PR #12 that implements the above and should fix your thread safety issue. Check it out and see if it resolves it, then I'll merge it.
@kirsle This library is not thread safe. It panics and raises fatal error in multi threaded environment. This is because you are not handling concurrent read and write of maps which is not thread safe in golang. Please see these posts for reference:
I'm also posting the error message for your reference.
Please resolve this bug.
A suggestion from my side is to use concurrent-map instead of golang inbuilt maps.