embotech/ecos

ECOS on Multithreaded program causes segmentation error

Closed this issue · 4 comments

I am calling ECOS from cvxpy in a multi-threaded program. The program breaks with exit code 139 which is the segment fault error. Any idea why this is happening?

I tested with other cvxpy solvers and they seem fine.

Getting rid of the static modifier on this line https://github.com/embotech/ecos-python/blob/master/src/ecosmodule.c#L55 fixes the problem for me. @echu how important is it to have that variable be static?

echu commented

Wow. That's really strange. Is it multithreaded or multiprocess? (i.e. import threading or import multiprocessing?)

I can't remember if I had a good reason for marking it static other than to save allocating a pointer on the stack frame every time. I'm not sure how Python multithreads it, but I'm guessing the static pointer isn't shared across threads, causing the problem.

Out of curiousity, has anyone tried using gevent with ECOS/CVXPY? I'm pretty sure it doesn't do much since gevent helps with IO-bound processes, but if it works fine, then this static modifier is definitely the culprit.

In any case, I don't imagine it being terribly important, and we seem to gain a whole lot more. Why don't you (or someone else) submit a PR with that modifier removed? We'll make sure it makes it to the next release.

Alternatively, for those that are still stuck on this one (2.0.2, I think?), you'll have to install from source from the (incoming) PR (for now).

I'll also make sure to add a test case for multithreading / multiprocessing in this library so we don't run into the same problem in the future.

echu commented

Closing this issue, since it seems we fixed it. Please follow up if this is still causing issues on ECOS version > 2.0.2