Skip to content

Commit

Permalink
Avoid probes interval blocking shutdown
Browse files Browse the repository at this point in the history
The probes instance starts an interval timer on initialisation.
By default, timers cause the Node.js engine to await their
completion on shutdown -- which, this being an interval timer, is
never actually completed. (See #418)

We fixed this in the past by implementing `Appsignal.stop`, which
clears the interval. But a preferable solution is to mark the
probes' interval as `.unref()`, telling the Node.js engine that it
does not need to be awaited.
  • Loading branch information
unflxw committed Sep 5, 2024
1 parent 946fbb4 commit dc54522
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changesets/do-not-block-node-js-shutdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: change
---

Do not block Node.js shutdown. It is no longer necessary to call `Appsignal.stop` for the Node.js engine to allow itself to shut down. It should still be called and awaited in production scenarios and at the end of scripts, as it ensures that scheduled check-ins are delivered.
2 changes: 1 addition & 1 deletion src/probes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BaseProbeRunner extends EventEmitter implements ProbeRunner {
public register(name: string, fn: () => void): void {
this.#timers.set(
name,
setInterval(() => this.emit(name), 60 * 1000)
setInterval(() => this.emit(name), 60 * 1000).unref()
)

this.removeAllListeners(name)
Expand Down

0 comments on commit dc54522

Please sign in to comment.