@tramvai/module-common 4.41.107 → 4.41.111

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.
@@ -9,7 +9,7 @@ function runInAsyncContext({ app, storage, }) {
9
9
  storage.run({}, done);
10
10
  // prevent memory leaks, because async context can be destroyed after response,
11
11
  // all stored resources will be accumulated in memory, and peak memory allocation will be high
12
- // `onResponse` is not used because is not fired when request was aborted by user (https://fastify.dev/docs/latest/Guides/Detecting-When-Clients-Abort/)
12
+ // `onResponse` is not enough because is not fired when request was aborted by user (https://fastify.dev/docs/latest/Guides/Detecting-When-Clients-Abort/)
13
13
  // TODO: can lead to errors because store will be cleared before reply, but maybe it's ok because response will be ignored?
14
14
  reply.raw.once('close', () => {
15
15
  const store = storage.getStore();
@@ -20,6 +20,16 @@ function runInAsyncContext({ app, storage, }) {
20
20
  }
21
21
  });
22
22
  });
23
+ // we still need to clear store on response, because socket "close" event can not be executed for a long time,
24
+ // because we use `http.Agent` with `keepAlive` enabled, and socket can be reused.
25
+ app.addHook('onResponse', async () => {
26
+ const store = storage.getStore();
27
+ if (store) {
28
+ for (const key in store) {
29
+ delete store[key];
30
+ }
31
+ }
32
+ });
23
33
  }
24
34
  let AsyncLocalStorageModule = class AsyncLocalStorageModule {
25
35
  };
@@ -13,7 +13,7 @@ function runInAsyncContext({ app, storage, }) {
13
13
  storage.run({}, done);
14
14
  // prevent memory leaks, because async context can be destroyed after response,
15
15
  // all stored resources will be accumulated in memory, and peak memory allocation will be high
16
- // `onResponse` is not used because is not fired when request was aborted by user (https://fastify.dev/docs/latest/Guides/Detecting-When-Clients-Abort/)
16
+ // `onResponse` is not enough because is not fired when request was aborted by user (https://fastify.dev/docs/latest/Guides/Detecting-When-Clients-Abort/)
17
17
  // TODO: can lead to errors because store will be cleared before reply, but maybe it's ok because response will be ignored?
18
18
  reply.raw.once('close', () => {
19
19
  const store = storage.getStore();
@@ -24,6 +24,16 @@ function runInAsyncContext({ app, storage, }) {
24
24
  }
25
25
  });
26
26
  });
27
+ // we still need to clear store on response, because socket "close" event can not be executed for a long time,
28
+ // because we use `http.Agent` with `keepAlive` enabled, and socket can be reused.
29
+ app.addHook('onResponse', async () => {
30
+ const store = storage.getStore();
31
+ if (store) {
32
+ for (const key in store) {
33
+ delete store[key];
34
+ }
35
+ }
36
+ });
27
37
  }
28
38
  exports.AsyncLocalStorageModule = class AsyncLocalStorageModule {
29
39
  };
@@ -136,7 +136,7 @@ class CommandLineRunner {
136
136
  }
137
137
  // eslint-disable-next-line class-methods-use-this
138
138
  throwError(err, di) {
139
- if (typeof err === 'object') {
139
+ if (process.env.NODE_ENV === 'development' && typeof err === 'object') {
140
140
  // eslint-disable-next-line no-param-reassign
141
141
  err.di = di;
142
142
  }
@@ -136,7 +136,7 @@ class CommandLineRunner {
136
136
  }
137
137
  // eslint-disable-next-line class-methods-use-this
138
138
  throwError(err, di) {
139
- if (typeof err === 'object') {
139
+ if (process.env.NODE_ENV === 'development' && typeof err === 'object') {
140
140
  // eslint-disable-next-line no-param-reassign
141
141
  err.di = di;
142
142
  }
@@ -140,7 +140,7 @@ class CommandLineRunner {
140
140
  }
141
141
  // eslint-disable-next-line class-methods-use-this
142
142
  throwError(err, di) {
143
- if (typeof err === 'object') {
143
+ if (process.env.NODE_ENV === 'development' && typeof err === 'object') {
144
144
  // eslint-disable-next-line no-param-reassign
145
145
  err.di = di;
146
146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-common",
3
- "version": "4.41.107",
3
+ "version": "4.41.111",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -36,30 +36,30 @@
36
36
  "@tinkoff/lru-cache-nano": "^7.9.0",
37
37
  "@tinkoff/pubsub": "0.7.3",
38
38
  "@tinkoff/url": "0.10.3",
39
- "@tramvai/experiments": "4.41.107",
40
- "@tramvai/module-cookie": "4.41.107",
41
- "@tramvai/module-environment": "4.41.107",
42
- "@tramvai/module-log": "4.41.107",
39
+ "@tramvai/experiments": "4.41.111",
40
+ "@tramvai/module-cookie": "4.41.111",
41
+ "@tramvai/module-environment": "4.41.111",
42
+ "@tramvai/module-log": "4.41.111",
43
43
  "@tramvai/safe-strings": "0.7.9",
44
- "@tramvai/tokens-child-app": "4.41.107",
45
- "@tramvai/tokens-common": "4.41.107",
46
- "@tramvai/tokens-core-private": "4.41.107",
47
- "@tramvai/tokens-metrics": "4.41.107",
48
- "@tramvai/tokens-render": "4.41.107",
49
- "@tramvai/tokens-router": "4.41.107",
50
- "@tramvai/tokens-server-private": "4.41.107",
51
- "@tramvai/types-actions-state-context": "4.41.107",
44
+ "@tramvai/tokens-child-app": "4.41.111",
45
+ "@tramvai/tokens-common": "4.41.111",
46
+ "@tramvai/tokens-core-private": "4.41.111",
47
+ "@tramvai/tokens-metrics": "4.41.111",
48
+ "@tramvai/tokens-render": "4.41.111",
49
+ "@tramvai/tokens-router": "4.41.111",
50
+ "@tramvai/tokens-server-private": "4.41.111",
51
+ "@tramvai/types-actions-state-context": "4.41.111",
52
52
  "hoist-non-react-statics": "^3.3.1"
53
53
  },
54
54
  "peerDependencies": {
55
- "@tinkoff/dippy": "0.10.11",
55
+ "@tinkoff/dippy": "0.10.12",
56
56
  "@tinkoff/utils": "^2.1.2",
57
- "@tramvai/cli": "4.41.107",
58
- "@tramvai/core": "4.41.107",
59
- "@tramvai/papi": "4.41.107",
60
- "@tramvai/react": "4.41.107",
61
- "@tramvai/state": "4.41.107",
62
- "@tramvai/tokens-server": "4.41.107",
57
+ "@tramvai/cli": "4.41.111",
58
+ "@tramvai/core": "4.41.111",
59
+ "@tramvai/papi": "4.41.111",
60
+ "@tramvai/react": "4.41.111",
61
+ "@tramvai/state": "4.41.111",
62
+ "@tramvai/tokens-server": "4.41.111",
63
63
  "react": ">=16.14.0",
64
64
  "tslib": "^2.4.0"
65
65
  },