'`Out of shared memory` error occurs when running Flow.js inside AWS Lambda

I am trying to run Flow inside AWS Lambda using NodeJS 12 child_process.spawn() method and struggling to get correct results. When I call flow executable just for basic info with --help parameter, it works well. However, when trying to do a real type check, I get Out of shared memory crash.

This is how I call the binary:

import { spawn } from 'child_process'

const FLOW_BINARY = '/var/task/flow/flow'

let args = [
  'check',
  '--sharedmemory-log-level', '1',
  '--verbose',
  '--verbose-flowlib',
  //'--max-workers', '1', // tried to limit number of workers
  //'--temp-dir=/tmp/flow', // tried to explicitly specify temp directory 
  '.',
]

const options = {
  'cwd': '/var/task/flow/',
  'stdio': ['pipe', 'pipe', 'pipe', 'pipe'],
}

spawn(FLOW_BINARY, args, options)

Execution of the binary ends with exit code 15:

executable=/var/task/flow/flow
version=0.137.0
No saved state available
Parsing
Out of shared memory:
Raised by primitive operation at file "src/heap/sharedMem.ml", line 256, characters 60-70
Called from file "src/heap/workerCancel.ml", line 27, characters 6-10

I've already also tried to compile Flow myself specifically for Amazon Linux 2 matching exactly system libraries and so on but haven't seen any difference. I am not very familiar with OCaml and Flow codebase so maybe I am just missing some basic principal or config param. It would be very helpful if someone can help me understand the shared memory usage or point me in some direction. I am also happy to pass some build flags to the custom Flow build if it helps.

Thank you very much :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source