govuk-docker icon indicating copy to clipboard operation
govuk-docker copied to clipboard

Fixture file based tests fail due to Linux Kernel issue

Open kevindew opened this issue 2 years ago • 1 comments

People have experienced problems running the test suites of Content Publisher and Whitehall (I'm not aware of other apps but there could be more) using govuk-docker. It transpires this issue is a problem with the Linux kernel, in particular the version that Docker-for-mac is using currently (on my machine it's 5.10.47-linuxkit) but I'm recording this here so the GOV.UK issue is documented and can be tracked to a degree.

The evidence of the problem is tests that fail like so:

     MiniMagick::Invalid:
       `identify /tmp/mini_magick20211206-1-7orhba.jpg` failed with error:
       identify-im6.q16: insufficient image data in file `/tmp/mini_magick20211206-1-7orhba.jpg' @ error/jpeg.c/ReadJPEGImage_/1166.

or

Error:
ImageUploaderTest#test_should_store_all_the_versions_of_a_bitmap_image_in_asset_manager:
CarrierWave::ProcessingError: Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: `convert /govuk/whitehall/tmp/1321009871-957757668381030-0168-8098/s960/minister-of-funk.960x640.jpg -auto-orient -resize 960x640^ -gravity Center -background rgba(255,255,255,0.0) -extent 960x640 /tmp/image_processing20111111-428-11fn1kn.jpg` failed with error:
convert-im6.q16: insufficient image data in file `/govuk/whitehall/tmp/1321009871-957757668381030-0168-8098/s960/minister-of-funk.960x640.jpg' @ error/jpeg.c/ReadJPEGImage_/1166.
convert-im6.q16: no images defined `/tmp/image_processing20111111-428-11fn1kn.jpg' @ error/convert.c/ConvertImageCommand/3229.

The source of the issue is a relatively obscure set of circumstances: a file is stored on a docker mount (i.e. a test fixture), it is then copied to be a temporary file (i.e. a test faking the upload of a file) and then is copied again (i.e copying the uploaded file for processing).

The issue is discussed (at length) in: https://github.com/docker/for-linux/issues/1015. It looks like versions of Linux Kernel > 5.10 are fixed and it appears that a backported fix for 5.10 is imminent, however it's completely unclear how long it will take for any fixes to make their way into a Docker-for-mac releases.

The two options I see ahead of us for this are:

  1. Wait it out, expect that a future release of Docker Desktop for mac resolves it
  2. Refactor test code that is affected by this issue to no longer be affected by the circumstances - there seems to be some examples based off the issue

By default, we're effectively doing 1) now - I imagine if this issue continues for multiple months we may switch to taking 2)

kevindew avatar Dec 07 '21 11:12 kevindew

I've implemented a workaround for the Whitehall and Content Publisher apps in #539, which follows an approach laid out in a comment on docker/for-linux#1015.

In short: it turns out the bug doesn't occur when /tmp is mounted as a tmpfs volume.

ollietreend avatar Dec 07 '21 15:12 ollietreend