haskellkubernetesoutput-buffering

No stdout/stderror output or delayed when running Haskell application in Kubernetes


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/


Solution

  • 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!