@hile/micro 3.0.3 → 3.0.6

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.
@@ -124,6 +124,15 @@ export class Application extends Server {
124
124
  this._registryLookupTimeoutMs = registryLookupTimeoutMs;
125
125
  this._requestTimeoutMs = requestTimeoutMs;
126
126
  this._circuitBreaker = resolveCircuitBreakerOptions(circuitBreaker);
127
+ this.events.on('disconnect', (client) => {
128
+ const disconnectedKey = `${client.host}:${client.port}`;
129
+ // 一个物理连接可承载多个 namespace;集中清理可避免每次服务发现都向 Client 重复注册监听器。
130
+ for (const [namespace, stack] of this.namespaces) {
131
+ if (`${stack.host}:${stack.port}` !== disconnectedKey)
132
+ continue;
133
+ this.namespaces.delete(namespace);
134
+ }
135
+ });
127
136
  this.register('/-/health', async () => ({
128
137
  status: 'ok',
129
138
  registry: !!this.registry,
@@ -711,12 +720,6 @@ export class Application extends Server {
711
720
  }
712
721
  return client;
713
722
  });
714
- }).then(client => {
715
- client.events.on('disconnect', () => {
716
- if (this.namespaces.has(namespace)) {
717
- this.namespaces.delete(namespace);
718
- }
719
- });
720
723
  }).catch(e => {
721
724
  // Registry unavailable but previously cached client still valid -> degrade
722
725
  const cachedKey = `${cachedHost}:${cachedPort}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/micro",
3
- "version": "3.0.3",
3
+ "version": "3.0.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -31,5 +31,5 @@
31
31
  "ws": "^8.21.0",
32
32
  "yaml": "^2.9.0"
33
33
  },
34
- "gitHead": "eac3a74c71ec2c514b920015f1c0d3415d3b8057"
34
+ "gitHead": "f0ca6e772602138dd50bf5acd2f9d940b4fe505e"
35
35
  }