collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

thread safety #187

Open ghost opened 4 years ago

ghost commented 4 years ago

I'm looking into using this library but I can't find any info on whether it's threadsafe or not? Thanks for any intel!

jtschulz commented 4 years ago

Hey, just bumping this issue. Did you ever figure this out @mengelseatz ?

ghost commented 4 years ago

@PepperTeasdale I haven't and there were no replies. I'm assuming it's thread safe but haven't done a deep dive into the code yet.

alex-kovshovik commented 2 years ago

It looks like it might not be: we may have accidentally charged $X to one customer that was meant for another customer. And this is the reason I'm here. For some reason, we used an organizer with a few interactions to process the credit card charges. Each charge is processed as an individual Sidekiq job, and multiple jobs can be processed in parallel in the same Ruby process.

Every time I see calls like PayCharge.call(...) - this always raises a warning: "this is a class method call, need to be careful here"...

I wonder how context works interactors... is it thread-safe?

gaffneyc commented 2 years ago

Yes, Interactor is thread safe in that you can call .call from multiple threads and each call generates a new context.

However, if you initialize an Interactor (i.e. call .new) then that instance is not thread safe and shouldn't be shared with multiple threads.