Skip to content

Fix type codec cache races #301

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

Merged
merged 1 commit into from
Jun 1, 2018
Merged

Fix type codec cache races #301

merged 1 commit into from
Jun 1, 2018

Conversation

elprans
Copy link
Member

@elprans elprans commented May 31, 2018

Current global type codec cache works poorly in a pooled environment.
The global nature of the cache makes introspection/cache bust race a
frequent occurrence. Additionally, busting the codec cache in all
connections only because one of them had reconfigured a codec seems
wrong.

The fix is simple: every connection now has its own codec cache. The
downside is that there will be more introspection queries on fresh
connections, but given that most connections in the field are pooled,
the robustness gains are more important.

Fixes: #278

@elprans elprans requested a review from 1st1 May 31, 2018 23:37
self._protocol.get_settings().register_data_types(types)
need_reprepare = False
types_with_missing_codecs = statement._init_types()
while types_with_missing_codecs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a MAX_ITER constant and raise an exception if we loop more times than it (in case we have a bug in out logic that will make it easier for people to report it)

@@ -326,6 +332,11 @@ def is_in_transaction(self):

return statement

async def _introspect_types(self, typeoids, timeout):
types, intro_stmt = await self.__execute(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return await

Current global type codec cache works poorly in a pooled environment.
The global nature of the cache makes introspection/cache bust race a
frequent occurrence.  Additionally, busting the codec cache in _all_
connections only because one of them had reconfigured a codec seems
wrong.

The fix is simple: every connection now has its own codec cache.  The
downside is that there will be more introspection queries on fresh
connections, but given that most connections in the field are pooled,
the robustness gains are more important.

Fixes: #278
@elprans elprans merged commit 482a186 into master Jun 1, 2018
@elprans elprans deleted the codec-cache branch June 1, 2018 14:02
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.

RuntimeError: no decoder for OID 3910
2 participants