Skip to content

Can context['model'] be shared between threads? #81

@jeancochrane

Description

@jeancochrane

I'm trying to determine whether ckanext-pages is responsible for a race condition that brought down our application last night. I'm wondering if you can help me figure out how to interpret the context['model'] object to see if it's possible that it could have been shared between two threads. Specifically, I'm interested in this code block:

def _pages_list(context, data_dict):
search = {}
if db.pages_table is None:
db.init_db(context['model'])

What would you expect context['model'] to represent in this case? It looks like db.py modifies in a number of different ways, including setting table mappings:

global pages_table
pages_table = sa.Table('ckanext_pages', model.meta.metadata,
sa.Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
sa.Column('title', types.UnicodeText, default=u''),
sa.Column('name', types.UnicodeText, default=u''),
sa.Column('content', types.UnicodeText, default=u''),
sa.Column('lang', types.UnicodeText, default=u''),
sa.Column('order', types.UnicodeText, default=u''),
sa.Column('private',types.Boolean,default=True),
sa.Column('group_id', types.UnicodeText, default=None),
sa.Column('user_id', types.UnicodeText, default=u''),
sa.Column('publish_date', types.DateTime),
sa.Column('page_type', types.DateTime),
sa.Column('created', types.DateTime, default=datetime.datetime.utcnow),
sa.Column('modified', types.DateTime, default=datetime.datetime.utcnow),
sa.Column('extras', types.UnicodeText, default=u'{}'),
extend_existing=True
)
model.meta.mapper(
Page,
pages_table,
)

This was the block of code that caused my errors in question, so any guidance you might have to shed light on what's supposed to happen with the model object would be helpful. If you're interested in deeper context, you can see a more detailed investigation into our outage here: opendataphilly/opendataphilly-ckan#92 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions