paed01/bpmn-engine

Timer warning (does not fit into a 32-bit signed integer)

rusaym opened this issue · 3 comments

rusaym commented

Hi, I got a warning with some dates using Timer, and process crashes after the warning.

Here is an example:

const { Engine } = require('bpmn-engine')
const { EventEmitter } = require('events')
const fs = require('fs-extra')

const source = fs.readFileSync('./test1.bpmn')

const notifyUser = () => {
  console.log('Script task executed')
}

const engine = new Engine({
  name: 'execution example',
  source,
  moddleOptions: {
    camunda: require('camunda-bpmn-moddle/resources/camunda'),
  },
  variables: {
    taskDate: '2024-05-16T12:18:00.000Z',
  },
  services: {
    notifyUser,
  },
})
const listener = new EventEmitter()

listener.on('activity.timeout', (api, execution) => {
  console.log('Time out!')
})

engine.execute(
  {
    listener,
  },
  (err) => {
    if (err) throw err
  }
)

If I set taskDate: '2023-05-16T12:18:00.000Z' there is no problem, but if I change it to this taskDate: '2024-05-16T12:18:00.000Z' I got a warning:

(node:45452) TimeoutOverflowWarning: 31705610336 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
(Use `node --trace-warnings ...` to show where the warning was created)

Maybe there is some special date format to avoid this?

paed01 commented

Yep. The max delay for setTimeout is 2,147,483,647. The default timer-handler doesn't handle that unfortunately. I suggest that you make a copy of the Timer-class, make a modification to ignore values above max-delay, and supply it to the engine as an option. While I try to figure out how to handle this...

paed01 commented

Should be solved by 48041e4. Released as bpmn-engine@16.0.1.

rusaym commented

Thank you, now it's working!