@vibedeckx/linux-x64 0.3.3 → 0.3.4

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.
@@ -50,25 +50,15 @@ var eventEmitter2_1 = require("./eventEmitter2");
50
50
  * the timer has started.
51
51
  */
52
52
  var FLUSH_DATA_INTERVAL = 1000;
53
- /**
54
- * Connects to and manages the lifecycle of the conout socket. This socket must be drained on
55
- * another thread in order to avoid deadlocks where Conpty waits for the out socket to drain
56
- * when `ClosePseudoConsole` is called. This happens when data is being written to the terminal when
57
- * the pty is closed.
58
- *
59
- * See also:
60
- * - https://github.com/microsoft/node-pty/issues/375
61
- * - https://github.com/microsoft/vscode/issues/76548
62
- * - https://github.com/microsoft/terminal/issues/1810
63
- * - https://docs.microsoft.com/en-us/windows/console/closepseudoconsole
64
- */
65
53
  var ConoutConnection = /** @class */ (function () {
66
54
  function ConoutConnection(_conoutPipeName, _useConptyDll) {
67
55
  var _this = this;
68
56
  this._conoutPipeName = _conoutPipeName;
69
57
  this._useConptyDll = _useConptyDll;
70
58
  this._isDisposed = false;
59
+ this._isReady = false;
71
60
  this._onReady = new eventEmitter2_1.EventEmitter2();
61
+ this._onError = new eventEmitter2_1.EventEmitter2();
72
62
  var workerData = {
73
63
  conoutPipeName: _conoutPipeName
74
64
  };
@@ -77,18 +67,34 @@ var ConoutConnection = /** @class */ (function () {
77
67
  this._worker.on('message', function (message) {
78
68
  switch (message) {
79
69
  case 1 /* ConoutWorkerMessage.READY */:
70
+ _this._isReady = true;
80
71
  _this._onReady.fire();
81
72
  return;
82
73
  default:
83
74
  console.warn('Unexpected ConoutWorkerMessage', message);
84
75
  }
85
76
  });
77
+ this._worker.on('error', function (error) {
78
+ if (!_this._isDisposed && !_this._isReady) {
79
+ _this._onError.fire(error);
80
+ }
81
+ });
82
+ this._worker.on('exit', function (code) {
83
+ if (!_this._isDisposed && !_this._isReady) {
84
+ _this._onError.fire(new Error("Conout worker exited before connecting (code ".concat(code, ")")));
85
+ }
86
+ });
86
87
  }
87
88
  Object.defineProperty(ConoutConnection.prototype, "onReady", {
88
89
  get: function () { return this._onReady.event; },
89
90
  enumerable: false,
90
91
  configurable: true
91
92
  });
93
+ Object.defineProperty(ConoutConnection.prototype, "onError", {
94
+ get: function () { return this._onError.event; },
95
+ enumerable: false,
96
+ configurable: true
97
+ });
92
98
  ConoutConnection.prototype.dispose = function () {
93
99
  if (!this._useConptyDll && this._isDisposed) {
94
100
  return;
@@ -21,13 +21,19 @@ var conptyNative;
21
21
  * has started.
22
22
  */
23
23
  var FLUSH_DATA_INTERVAL = 1000;
24
+ var CONNECTION_TIMEOUT = 5000;
25
+ var defaultWindowsPtyAgentOptions = {
26
+ connectionTimeout: CONNECTION_TIMEOUT,
27
+ conoutConnectionFactory: function (conoutPipeName, useConptyDll) { return new windowsConoutConnection_1.ConoutConnection(conoutPipeName, useConptyDll); }
28
+ };
24
29
  /**
25
30
  * This agent sits between the WindowsTerminal class and provides an interface for conpty.
26
31
  */
27
32
  var WindowsPtyAgent = /** @class */ (function () {
28
- function WindowsPtyAgent(file, args, env, cwd, cols, rows, debug, _useConptyDll, conptyInheritCursor) {
33
+ function WindowsPtyAgent(file, args, env, cwd, cols, rows, debug, _useConptyDll, conptyInheritCursor, options) {
29
34
  if (_useConptyDll === void 0) { _useConptyDll = false; }
30
35
  if (conptyInheritCursor === void 0) { conptyInheritCursor = false; }
36
+ if (options === void 0) { options = defaultWindowsPtyAgentOptions; }
31
37
  var _this = this;
32
38
  this._useConptyDll = _useConptyDll;
33
39
  this._innerPid = 0;
@@ -54,24 +60,26 @@ var WindowsPtyAgent = /** @class */ (function () {
54
60
  // We must wait for the worker to connect before calling conptyNative.connect()
55
61
  // to avoid blocking the Node.js event loop in ConnectNamedPipe.
56
62
  // See https://github.com/microsoft/node-pty/issues/763
57
- this._conoutSocketWorker = new windowsConoutConnection_1.ConoutConnection(term.conout, this._useConptyDll);
63
+ this._conoutSocketWorker = options.conoutConnectionFactory(term.conout, this._useConptyDll);
58
64
  // Store pending connection info - we'll complete the connection when worker is ready
59
65
  this._pendingPtyInfo = { pty: this._pty, commandLine: commandLine, cwd: cwd, env: env };
60
- // Timeout to ensure connection completes even if worker fails to signal ready
61
- var connectionTimeout = setTimeout(function () {
62
- if (_this._pendingPtyInfo) {
63
- // Worker never signaled ready - complete connection anyway to avoid zombie state
64
- _this._completePtyConnection();
65
- }
66
- }, 5000);
66
+ // Never call connect() before the worker is ready, as ConnectNamedPipe
67
+ // would block the Node.js event loop while waiting for the output client.
68
+ this._connectionTimeout = setTimeout(function () {
69
+ _this._failPtyConnection(new Error('Timed out waiting for ConPTY output worker'));
70
+ }, options.connectionTimeout);
67
71
  this._conoutSocketWorker.onReady(function () {
68
- clearTimeout(connectionTimeout);
72
+ if (!_this._pendingPtyInfo) {
73
+ return;
74
+ }
75
+ _this._clearConnectionTimeout();
69
76
  _this._conoutSocketWorker.connectSocket(_this._outSocket);
70
77
  // Now that the worker has connected to the output pipe, we can safely call
71
78
  // conptyNative.connect() which calls ConnectNamedPipe - it won't block because
72
79
  // the client (worker) is already connected
73
80
  _this._completePtyConnection();
74
81
  });
82
+ this._conoutSocketWorker.onError(function (error) { return _this._failPtyConnection(error); });
75
83
  this._outSocket.on('connect', function () {
76
84
  _this._outSocket.emit('ready_datapipe');
77
85
  });
@@ -119,6 +127,7 @@ var WindowsPtyAgent = /** @class */ (function () {
119
127
  if (!this._pendingPtyInfo) {
120
128
  return;
121
129
  }
130
+ this._clearConnectionTimeout();
122
131
  var _b = this._pendingPtyInfo, pty = _b.pty, commandLine = _b.commandLine, cwd = _b.cwd, env = _b.env;
123
132
  this._pendingPtyInfo = undefined;
124
133
  try {
@@ -126,8 +135,8 @@ var WindowsPtyAgent = /** @class */ (function () {
126
135
  this._innerPid = connect.pid;
127
136
  }
128
137
  catch (err) {
129
- // connect() runs from the conout worker's onReady callback (or its
130
- // timeout fallback), so a throw here would otherwise surface as an
138
+ // connect() runs from the conout worker's onReady callback, so a throw
139
+ // here would otherwise surface as an
131
140
  // uncaughtException with no way for the consumer to observe it.
132
141
  var code = (_a = /error code: (\d+)/.exec(err.message)) === null || _a === void 0 ? void 0 : _a[1];
133
142
  this._exitCode = code ? parseInt(code, 10) : -1;
@@ -141,6 +150,28 @@ var WindowsPtyAgent = /** @class */ (function () {
141
150
  this._onError.fire(err);
142
151
  }
143
152
  };
153
+ WindowsPtyAgent.prototype._failPtyConnection = function (error) {
154
+ if (!this._pendingPtyInfo) {
155
+ return;
156
+ }
157
+ this._clearConnectionTimeout();
158
+ this._pendingPtyInfo = undefined;
159
+ this._exitCode = -1;
160
+ try {
161
+ this._ptyNative.kill(this._pty, this._useConptyDll);
162
+ }
163
+ catch ( /* already gone */_a) { /* already gone */ }
164
+ this._conoutSocketWorker.dispose();
165
+ this._inSocket.destroy();
166
+ this._outSocket.destroy();
167
+ this._onError.fire(error);
168
+ };
169
+ WindowsPtyAgent.prototype._clearConnectionTimeout = function () {
170
+ if (this._connectionTimeout) {
171
+ clearTimeout(this._connectionTimeout);
172
+ this._connectionTimeout = undefined;
173
+ }
174
+ };
144
175
  WindowsPtyAgent.prototype.resize = function (cols, rows) {
145
176
  if (this._exitCode !== undefined) {
146
177
  throw new Error('Cannot resize a pty that has already exited');
@@ -153,6 +184,7 @@ var WindowsPtyAgent = /** @class */ (function () {
153
184
  WindowsPtyAgent.prototype.kill = function () {
154
185
  var _this = this;
155
186
  // Prevent deferred connection from completing after kill
187
+ this._clearConnectionTimeout();
156
188
  this._pendingPtyInfo = undefined;
157
189
  // Tell the agent to kill the pty, this releases handles to the process
158
190
  if (!this._useConptyDll) {
@@ -4,7 +4,7 @@
4
4
  "author": {
5
5
  "name": "Microsoft Corporation"
6
6
  },
7
- "version": "1.2.0-beta.14",
7
+ "version": "1.2.0-beta.15",
8
8
  "license": "MIT",
9
9
  "main": "./lib/index.js",
10
10
  "types": "./typings/node-pty.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedeckx/linux-x64",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Vibedeckx platform binaries for Linux x64",
5
5
  "os": [
6
6
  "linux"