No stdout/stderror output when running Haskell application in Kubernetes

1/1/2020

I've run into a very strange issue where I don't seem to be getting any stdout/stderr output from a Haskell application when run via Kubernetes.

I'm using very basic putStrLn to write to stdout.

If I manually enter the container within the Kubernetes environment and run the application via the shell - I see the expected output.

What may be the cause of this issue/

-- Chris Stryczynski
haskell
kubernetes
output-buffering

1 Answer

1/1/2020

It seems this is caused by the output buffering being set in "block" mode when being output to the kubernetes logging.

Fixed via setting the buffering to LineBuffering:

import System.IO

...
  hSetBuffering stdout LineBuffering
  hSetBuffering stderr LineBuffering

http://hackage.haskell.org/package/base-4.12.0.0/docs/System-IO.html#t:BufferMode

The default buffering mode when a handle is opened is implementation-dependent and may depend on the file system object which is attached to that handle. For most implementations, physical files will normally be block-buffered and terminals will normally be line-buffered.

Thanks to Jesse Kempf from the fp slack for pointing me to this!

-- Chris Stryczynski
Source: StackOverflow