Lua scripts making http requests

Hi,

While working on Orthanc over the weekend, I created a Lua plugin that made a call to my Orthanc C++ plugin via the HttpGet function. This ended up deadlocking Orthanc in MyIncomingHttpRequestFilter::IsAllowed() while attempting to get the Lua Context Lock (since the LuaContextLock was obtained and held by the call to my plugin). While Orthanc may not be designed for my use case, it occurred to me that no HTTP or CSTORE requests can complete while a Lua plugin is running since both of those require the LuaContextLock. A Lua plugin that makes a call to a web server via HttpGet can therefore have adverse affects on Orthanc’s performance for DICOM and web requests as such processing will be blocked for the duration of the Lua plugin web request. The Lua plugin web request could potentially take a look time to complete if the server is busy or down (network timeout). You may want to think about alternative designs for this or at least document this as something to take into consideration.

Chris

Hi,

Just added an issue to Orthanc bug tracker:
https://code.google.com/p/orthanc/issues/detail?id=15

Sébastien-

Hi Chris,

This problem is now fixed in the mainline. The fix will be part of release 0.9.1.

To make requests to the built-in API of Orthanc from Lua, you are invited to use:

  • RestApiGet(uri)
  • RestApiPost(uri, body)
  • RestApiPut(uri, body)
  • RestApiDelete(uri)

As these requests are issued from the Lua engine, they are now trusted by the Orthanc core, and the “MyIncomingHttpRequestFilter::IsAllowed()” is bypassed. As a consequence, the deadlock vanishes.

I have also added two convenience functions in Lua to convert between Lua values and JSON strings: “ParseJson(str)” and “DumpJson(value)”. These functions are very useful when calling the native REST API of Orthanc (or even remote Web services).

Sébastien-