K
K
keddad2020-01-09 17:03:45
PHP
keddad, 2020-01-09 17:03:45

Can a race condition in a multi-threaded application cause problems when working with the database and how to deal with it?

I have a Python - application with Huey (task manager). When I receive an external request, I call some pipeline, n times for each request:

pipe = (
        fetch_page.s(link)
            .then(process_page)
            .then(process_image)
    )

    huey.enqueue(pipe)


Essentially, every function in the pipeline, except for the first and last one, takes some _id, which corresponds to the document id in Mongo, and returns the _id. The problem is that these _ids do not always have time to be processed normally - that is, the first function sends a document to the database and returns some id, and the receiving function either catches an Exceptionon because GridFS cannot find the file, or returns None instead of an object if it is regular Mongo document. How can I get rid of such a lag? Now the only way I see is to force a delay between the launch of the pipeline functions, but this sounds like a disgusting option.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TheAndrey7, 2019-03-20
@matthewstafford

Different authorization methods have different levels of restrictions. For websites, they are the strictest, but Standalone already has the maximum capabilities.
Given these restrictions, there is nothing left to do but manually receive an access token and enter it into the database. The main thing is not to forget to take care of its reliable storage, otherwise access to the page can be obtained by outsiders.

K
keddad, 2020-03-25
@keddad

I realized that I forgot to answer the question here. No, if you didn't turn off the asknowledged writes function , this won't cause problems: by the time insert_one returns an ID, the document is guaranteed to be saved to the collection. Ref: stackoverflow.com/questions/59666342/does-pymongo-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question