Rapi: fully evaluate the body in getUrl
authorIustin Pop <iustin@google.com>
Wed, 5 Jan 2011 10:27:02 +0000 (11:27 +0100)
committerIustin Pop <iustin@google.com>
Fri, 7 Jan 2011 15:39:37 +0000 (16:39 +0100)
commitc9224fa4cab174e66b3e7167da79ad62399e2866
treeb9e626919c1164d7d5d4aeb2cb92d43babb86f87
parent4d8e5008f6656a15f80e590cc78cf7e7ab964c7f
Rapi: fully evaluate the body in getUrl

Currently, the Rapi.getUrl function returns the body without
evaluating it, and the other functions (loadData, parseData) do the
same. In effect, the top-level structure returned from loadData can be
a thunk which depends on the curl operation, thus keeping the curl
resources alive even after return from the Rapi module.

While this is not a problem in single-threaded programs, it can become
an issue with the threaded runtime. So it's better to fully evaluate
the HTTP body before returning from the getUrl function, so that at
least the curl resources are released.

Either "return $! body" or "(code, !body) <- …" works (i.e. avoids the
segfaults in my tests), but I think it's cleaner to force full
evaluation of the body when returning from the curlGetString
function. For this, we also enable the BangPatterns language
extension.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Balazs Lecz <leczb@google.com>
Ganeti/HTools/Rapi.hs