ddm-plugin-dubbo-support 0.2.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -68,15 +68,36 @@ class TelnetInvoker {
68
68
  // eslint-disable-next-line no-unused-vars
69
69
  return new Promise((resolve, reject) => {
70
70
  const socket = net__WEBPACK_IMPORTED_MODULE_1___default().createConnection(telnetPort, ip);
71
+ let settled = false;
72
+ const closeSocket = () => {
73
+ if (!socket.destroyed) {
74
+ socket.end();
75
+ }
76
+ };
77
+ const resolveAndClose = result => {
78
+ if (settled) {
79
+ return;
80
+ }
81
+ settled = true;
82
+ resolve(result);
83
+ closeSocket();
84
+ };
85
+ const rejectAndClose = error => {
86
+ if (settled) {
87
+ return;
88
+ }
89
+ settled = true;
90
+ reject(error);
91
+ closeSocket();
92
+ };
71
93
  socket.on('error', function (error) {
72
- resolve({
94
+ resolveAndClose({
73
95
  success: false,
74
96
  data: appMain__WEBPACK_IMPORTED_MODULE_0___default().pluginT("dubbo.invokePage.connectProviderError", {
75
97
  e: error
76
98
  }),
77
99
  elapsedTime: 0
78
100
  });
79
- socket.end();
80
101
  return;
81
102
  });
82
103
  const tSocket = new (telnet_stream__WEBPACK_IMPORTED_MODULE_2___default().TelnetSocket)(socket);
@@ -86,7 +107,7 @@ class TelnetInvoker {
86
107
  const result = mainBuffer.toString("utf8");
87
108
  // dubbo 3.0 未开启ip访问
88
109
  if (result.indexOf("Foreign Ip Not Permitted.") >= 0) {
89
- resolve({
110
+ resolveAndClose({
90
111
  success: false,
91
112
  data: "Dubbo 已开启禁止外网连接,请确保配置当前客户端IP可以连接或者使用Java方式进行调用",
92
113
  elapsedTime: 0
@@ -100,12 +121,11 @@ class TelnetInvoker {
100
121
  }
101
122
 
102
123
  // 解析结果
103
- resolve(this.resolveResponse(result));
124
+ resolveAndClose(this.resolveResponse(result));
104
125
  });
105
126
  socket.setTimeout(30000);
106
127
  socket.on("timeout", () => {
107
- reject(new Error(appMain__WEBPACK_IMPORTED_MODULE_0___default().pluginT("dubbo.invokePage.invokeTimeOut")));
108
- socket.end();
128
+ rejectAndClose(new Error(appMain__WEBPACK_IMPORTED_MODULE_0___default().pluginT("dubbo.invokePage.invokeTimeOut")));
109
129
  });
110
130
  tSocket.write(_common_TelnetUtils_js__WEBPACK_IMPORTED_MODULE_5__["default"].buildInvokeCommand({
111
131
  serviceName,