Comments (4)
There appears to be a bigger error here. Suppose I create a MongoConnection (which is really a ConnectionPool subclass) with 100 connections (pool_size=100). It looks like everything authenticates fine (_authenticated is True). But it then crashes sometimes in collection.py at line 318 in get_authenticated_protocol. Specifically, when another thread calls the an insert command, it gets to collection.insert, line 237 of insert:
if self._database._authenticated :
proto = yield self._database.connection.get_authenticated_protocol(self._database)
else :
proto = yield self._database.connection.getprotocol()
Since _authenticated is True, the call is made on line 237 to get_authenticatedProtocol. Here is what that looks like:
@defer.inlineCallbacks
def get_authenticated_protocol(self,database) :
# Get the next protocol available for communication in the pool
connection = self.__pool[self.__index]
database_name = str(database)
if database_name not in connection.auth_set :
name = self.cred_cache[database_name][0]
password = self.cred_cache[database_name][1]
yield self.authenticate_with_nonce(database,name,password)
else :
self.__index = (self.__index + 1) % self.__pool_size
defer.returnValue(connection.instance)
It crashes with a KeyError on line 318:
name = self.cred_cache[database_name][0]
This means that database_name is not in self.cred_cache!
Surprisingly enough, if we restart our process a few times, this issue goes away. But I really don't know why this error would pop up in the first place.
from txmongo.
Possible solution: in connection.py around line 291. Instead of adding database_name to the auth_set of current_connection, why not add it to ALL connections in the thread pool? Or are some previously opened connections then having their auth_sets emptied in clientConnectionLost?
Something's not right here when we have multiple connections in a connection pool.
from txmongo.
Hi! Please check out latest changes to txmongo. I've reworked all authentication-related stuff and my pull request was merged yesterday. Old authentication code had race conditions and was unstable with connection pool with pool_size > 1. Please test latest master branch in your scenarios.
Returning status of authentication is not that easy. MongoConnection is actually a connection pool and each individual connection in the pool might be active or inactive at any moment of time. What should authenticate()
return if all connections in the pool is not active (like just after creating MongoConnection instance in your example)? In this case authenticate()
just remembers that it needs to authenticate with specified credentials when any connection is going online.
My new implementation of authenticate()
behaves this way:
- If any connection in the pool is active when you call it, it will wait until all active connections will be authenticated (as long as you call it with
yield
of course) - If there is no active connections in the pool, it will return immediately
But your original example is the case 2, so it won't help you in this scenario.
I suggest you to issue some useless find_one()
right after authenticate()
and catch exception about failed authentication.
from txmongo.
Sounds like @pakedge needs a git pull.
Thanks @IlyaSkriblovsky.
from txmongo.
Related Issues (20)
- In disconnect: RuntimeError: dictionary changed size during iteration HOT 2
- When txmongo fails to connect mongodb, there is a memory leak HOT 8
- latest txmongo does not work with pymongo 3.7 HOT 3
- do not connect to mongodb+srv:// scheme HOT 1
- Does txmongo support compressors option? HOT 1
- builtins.AttributeError: '_CaseInsensitiveDictionary' object has no attribute 'copy' HOT 3
- Crash create_index: pymongo.errors.OperationFailure: cannot write to 'remains.system.indexes' HOT 2
- AssertionError: Tried to stop a LoopingCall that was not running. HOT 3
- txmongo not working with azure cosmos db HOT 19
- There should be a limit on the number of retries HOT 1
- insert_many does not work properly HOT 6
- maxIdleTimeMS support HOT 4
- does txmongo support transaction? HOT 2
- Proposing a PR to fix a few small typos HOT 1
- insert_many: unexpected keyword argument 'bypass_document_validation' in calling pymongo `_Bulk` HOT 2
- Import error with PyMongo==4.1.1. HOT 3
- Incompatible with mongodb >= 5.1 due to usage of deprecated `OP_QUERY` commands HOT 2
- txmongo with DocumentDB
- Incompatible with any version of DocumentDB HOT 3
- pymongo.errors.OperationFailure: TxMongo: not authorized for query on foo.test HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from txmongo.