grafana / pyroscope-nodejs

Pyroscope NodeJS integration
Apache License 2.0
27 stars 21 forks source link

make `.stop()` flush #26

Open eh-am opened 1 year ago

eh-am commented 1 year ago

This is going to be tricky.

When stopping the profiler, it only sets up a stop flag https://github.com/pyroscope-io/pyroscope-nodejs/blob/09d3f4d1b77d8640181e871db0fa3d60919e4a7d/src/index.ts#L284 Which only affects the next profiling round https://github.com/pyroscope-io/pyroscope-nodejs/blob/09d3f4d1b77d8640181e871db0fa3d60919e4a7d/src/index.ts#L257-L264

That means that it may take up to 10 seconds (the profiling round) to exit https://github.com/pyroscope-io/pyroscope-nodejs/blob/09d3f4d1b77d8640181e871db0fa3d60919e4a7d/src/index.ts#L204

This behaviour is pretty clear when running tests, where the test runner hangs up to 10 seconds, and the last profile captured is full of idle, since the program it's not doing anything.