Skip to content

OpenCV leaks TLS data when terminating OS threads #109

@basvandijk

Description

@basvandijk

The OpenCV C++ library uses Thread Local State (TLS). Unfortunately the TLS data is not freed when the OS thread terminates. See opencv/opencv#9745.

This is especially troublesome in Haskell where the runtime system by default executes FFI calls on random available OS threads. The user has no control over the lifetime of these OS threads which means there's a high risk of leaking OpenCV TLS data.

Until we find a solution in haskell-opencv we advise to do all OpenCV work on a bound Haskell thread (see forkOS or asyncBound) which ensures all FFI calls from that Haskell thread are done on the same OS thread. Then terminate these threads as little as possible.

Ping @ocharles, you might be suffering from this in production.

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