Skip to content

Poco::MongoDB connection pool and multithreading #860

@matejk

Description

@matejk

Hi,

Based on an example in the test suite for MongoDB we wanted to use connection pool and related MongoDB::PooledConnection in an a multi-threaded application. The concept seems ideal for that since the ObjectPool does all necessary housekeeping of available objects (connections to MongoDB database in this case).

However, strange behaviour was observed because requests in some of the threads received unexpected responses when using this approach with MongoDB 3.

A multi-threaded test case was prepared to reproduce the situation:

It creates new object in the main thread and spawns new thread to query and remove the object. In 6 cases out of 10 either creation of new object or query fails. Instead of receiving the expected "ok" response it gets a result from query which was requested by another thread or similar. Occasionally the test hangs because it expects response which is not delivered on that socket.

The connection is taken from the pool and then released for every request that is executed.

In the MongoDB documentation it is stated that requests can have client-defined requestID attached.

Do we need to use that?

Will MongoDB return result on the same socket where it was requested?

Any help or clarification would be appreciated.

Thanks,

Matej

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions