@platformatic/service 0.31.0 → 0.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,6 @@ const Fastify = require('fastify')
12
12
  // prometheus. It's an antipattern, so do
13
13
  // not use it elsewhere.
14
14
  let server = null
15
- let handler = null
16
15
 
17
16
  module.exports = fp(async function (app, opts) {
18
17
  let port = 9090
@@ -60,7 +59,6 @@ module.exports = fp(async function (app, opts) {
60
59
  if (server && server.address().port !== port) {
61
60
  await new Promise((resolve) => server.close(resolve))
62
61
  server = null
63
- handler = null
64
62
  }
65
63
 
66
64
  if (!server) {
@@ -71,12 +69,10 @@ module.exports = fp(async function (app, opts) {
71
69
 
72
70
  const promServer = Fastify({
73
71
  name: 'Prometheus server',
74
- serverFactory: (_handler) => {
75
- if (handler) {
76
- server.off('request', handler)
77
- }
78
- server.on('request', _handler)
79
- handler = _handler
72
+ serverFactory: (handler) => {
73
+ server.removeAllListeners('request')
74
+ server.removeAllListeners('clientError')
75
+ server.on('request', handler)
80
76
  return server
81
77
  },
82
78
  logger: app.log.child({ name: 'prometheus' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "0.31.0",
3
+ "version": "0.31.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -64,11 +64,11 @@
64
64
  "pino-pretty": "^10.0.0",
65
65
  "rfdc": "^1.3.0",
66
66
  "ua-parser-js": "^1.0.35",
67
- "@platformatic/client": "0.31.0",
68
- "@platformatic/config": "0.31.0",
69
- "@platformatic/swagger-ui-theme": "0.31.0",
70
- "@platformatic/types": "0.31.0",
71
- "@platformatic/utils": "0.31.0"
67
+ "@platformatic/client": "0.31.1",
68
+ "@platformatic/config": "0.31.1",
69
+ "@platformatic/swagger-ui-theme": "0.31.1",
70
+ "@platformatic/types": "0.31.1",
71
+ "@platformatic/utils": "0.31.1"
72
72
  },
73
73
  "standard": {
74
74
  "ignore": [
@@ -154,6 +154,29 @@ test('do not error on restart', async ({ teardown, equal, fail, match }) => {
154
154
  testPrometheusOutput(body)
155
155
  })
156
156
 
157
+ test('restarting 10 times does not leak', async ({ teardown, equal, fail, match }) => {
158
+ process.on('warning', (warning) => {
159
+ fail('warning was raised')
160
+ })
161
+ const app = await buildServer({
162
+ server: {
163
+ hostname: '127.0.0.1',
164
+ port: 0
165
+ },
166
+ metrics: true
167
+ })
168
+
169
+ teardown(async () => {
170
+ await app.close()
171
+ })
172
+
173
+ await app.start()
174
+
175
+ for (let i = 0; i < 10; i++) {
176
+ await app.restart()
177
+ }
178
+ })
179
+
157
180
  function testPrometheusOutput (output) {
158
181
  let metricBlock = []
159
182
  const lines = output.split('\n')