We were encountering some errors when saving specific JPEG images.
The error was shown in stderr as:
IOError: encoder error -2 when writing image file
And on stdout it printed:
Suspension not allowed here
The problem was the bufsize not contemplating the icc_profile block.