[Haskell-cafe] Space leak in WAI 3.0 application

Bardur Arantsson spam at scientician.net
Thu Nov 20 05:59:47 UTC 2014


On 2014-11-20 05:40, Thomas Koster wrote:
> 
> Thanks for your reply.
> 
> My coding style makes heavy use of let to keep lines succinct so am I
> going to have to be more careful about the order of lets in case I
> accidentally introduce unwanted sharing?
> 
> I was able to re-arrange the leaky version A into version B in my
> example, but I may not be able to do this in my real application. What
> if I need the first few bytes of "largeLBS" to determine the response
> status code or headers? This is only possible in version A.
> 

I would recommend avoiding lazy I/O altogether and using
"responseStream" instead. This will let you decide exactly what to write
and when.

> Or will replacing the lazy bytestring with a streaming abstraction
> like pipes or conduit make the problem go away in both versions?

Not magically, but both of those can certainly be used to avoid the
problem. You'll still have to arrange it so that you don't close over
a huge (lazy) byte string.

If what you're trying to do is simple, then I'd just recommend writing
your responses using "responseStream" and writing your "genereate
output" function in terms of the "write" and "flush" callbacks you get
access to write "responseStream". It's pretty easy when you get the hang
of it.

Regards,



More information about the Haskell-Cafe mailing list