Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sessions threadsafe #234

Closed
wants to merge 30 commits into from
Closed

Make sessions threadsafe #234

wants to merge 30 commits into from

Conversation

AusIV
Copy link

@AusIV AusIV commented Feb 21, 2017

I ran into the thread safety issue described here:

#153

According to boto3's docs, each thread should have its own session instance:

http://boto3.readthedocs.io/en/latest/guide/resources.html#multithreading

I resolved this by modifying the session property on the connection
class. It makes self._session into a thread local variable, and
attaches a session to self._session.session. The session property still
has the same behavior, but now it's creating a session on a
per-connection-per-thread basis instead of just on a per-thread basis.

This issue was intermittent to begin with, and I hadn't figured out a
way to reliably reproduce it, or I would have written a test. It still
passes PynamoDB's unit tests, and I haven't run into the thread safety
issue described in #153 since I've been running the patched version.

I ran into the thread safety issue described here:

pynamodb#153

According to boto3's docs, each thread should have its own session instance:

http://boto3.readthedocs.io/en/latest/guide/resources.html#multithreading

I resolved this by modifying the session property on the connection
class. It makes self._session into a thread local variable, and
attaches a session to self._session.session. The session property still
has the same behavior, but now it's creating a session on a
per-connection-per-thread basis instead of just on a per-thread basis.

This issue was intermittent to begin with, and I hadn't figured out a
way to reliably reproduce it, or I would have written a test. It still
passes PynamoDB's unit tests, and I haven't run into the thread safety
issue described in pynamodb#153 since I've been running the patched version.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.0005%) to 97.734% when pulling dc7332b on AusIV:devel into e5858ef on jlafon:devel.

4 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.0005%) to 97.734% when pulling dc7332b on AusIV:devel into e5858ef on jlafon:devel.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0005%) to 97.734% when pulling dc7332b on AusIV:devel into e5858ef on jlafon:devel.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0005%) to 97.734% when pulling dc7332b on AusIV:devel into e5858ef on jlafon:devel.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0005%) to 97.734% when pulling dc7332b on AusIV:devel into e5858ef on jlafon:devel.

@AusIV
Copy link
Author

AusIV commented Feb 21, 2017

Not sure why the checks failed on Python 2.6. It doesn't look like it even executed the tests.

@garrettheel garrettheel closed this May 2, 2017
@garrettheel garrettheel changed the base branch from devel to master May 2, 2017 21:59
@garrettheel
Copy link
Member

Reopening with new default branch

@garrettheel garrettheel reopened this May 2, 2017
Jean-Charles BERTIN and others added 10 commits June 6, 2017 09:30
I ran into the thread safety issue described here:

pynamodb#153

According to boto3's docs, each thread should have its own session instance:

http://boto3.readthedocs.io/en/latest/guide/resources.html#multithreading

I resolved this by modifying the session property on the connection
class. It makes self._session into a thread local variable, and
attaches a session to self._session.session. The session property still
has the same behavior, but now it's creating a session on a
per-connection-per-thread basis instead of just on a per-thread basis.

This issue was intermittent to begin with, and I hadn't figured out a
way to reliably reproduce it, or I would have written a test. It still
passes PynamoDB's unit tests, and I haven't run into the thread safety
issue described in pynamodb#153 since I've been running the patched version.
@jcbertin jcbertin mentioned this pull request Oct 20, 2017
@jpinner-lyft
Copy link
Contributor

replaced by #393

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet