[ome-devel] API call can crash server 5.1.4

Josh Moore josh at glencoesoftware.com
Mon Feb 15 10:01:49 GMT 2016


On Fri, Feb 12, 2016 at 8:56 PM, Damir Sudar <dsudar at lbl.gov> wrote:
> Hi all,

Hi Damir,

some explanation on what's happening below to go along with Ola's
query suggestions:


> An excerpt of the code that causes the crash is here:
>
> const std::string orphanedImagesQueryString =
>     "select img from Image as img "
>     "left outer join fetch img.datasetLinks as idl "
>     "left outer join fetch idl.parent as dst "
>     "left outer join fetch img.fileset as fs "
>     "join fetch fs.usedFiles as uf "
>     "join fetch uf.originalFile as of "
>     "join fetch img.pixels as pxl "
>     "join fetch pxl.pixelsType as pxt ";
> //  "where dst.id is null";

Without the where clause, this amounts to loading every image in the
database, which for a database with any series size can be harmful.


> omero::sys::ParametersIPtr dsParams = new omero::sys::ParametersI();
> dsParams->addLong("id", omero::rtypes::rlong(803));
> auto imageObjects = query->findAllByQuery(orphanedImagesQueryString,
> dsParams);
> for (auto image : omero::cast<omero::model::ImagePtr>(imageObjects)) {
>     std::cout << "i: "  << image->getId()->getValue() << " " <<
> image->getName()->getValue() << "\n";
> }

To prevent this type of overloading, you can and should enable paging
for queries:

https://github.com/openmicroscopy/openmicroscopy/blob/v5.2.1/components/tools/OmeroCpp/test/unit/parameters.cpp#L72

If you want to know how many pages there are, you can start off with a
"select count(img)"-style query. For this to work, you'll likely need
to add in an order clause, and potentially a distinct, depending on
the query. e.g.

  select distinct img from Image as img
  left outer join ...
  order by img.id desc


> I'm not sure, but as I understand, the crash occured when I commented "where
> dst.id is null" condition. The query with "where dst.id is null" didn't
> return result and I tried to remove the  "is null" condition - to see what
> would happen. And the server crashed.

Without the logs, it's hard to know which components had issues, but
at least one of them will have had memory issues and potentially your
sessions timed out due to other components hanging.

~Josh


> It appears that the server crashed when we tried to query images without
> parent dataset ("orphaned images”). I.e. something related to handling a
> situation where a parent pointer is NULL.
>
> - Damir


More information about the ome-devel mailing list