Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 864ee78

Browse filesBrowse files
SteveSandersonMSryanbrandenburg
authored andcommitted
Update NodeServices/SpaServices/NodeServices.Sockets to build using latest TypeScript and Webpack (aspnet#1748)
1 parent b5abf2a commit 864ee78
Copy full SHA for 864ee78

File tree

Expand file treeCollapse file tree

15 files changed

+13542
-600
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

15 files changed

+13542
-600
lines changed
Open diff view settings
Collapse file

‎src/Microsoft.AspNetCore.NodeServices.Sockets/Content/Node/entrypoint-socket.js‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.NodeServices.Sockets/Content/Node/entrypoint-socket.js
+147-60Lines changed: 147 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,114 @@
11
(function (e, a) { for (var i in a) e[i] = a[i]; }(exports, /******/(function (modules) { // webpackBootstrap
22
/******/ // The module cache
33
/******/ var installedModules = {};
4-
4+
/******/
55
/******/ // The require function
66
/******/ function __webpack_require__(moduleId) {
7-
7+
/******/
88
/******/ // Check if module is in cache
9-
/******/ if (installedModules[moduleId])
9+
/******/ if (installedModules[moduleId]) {
1010
/******/ return installedModules[moduleId].exports;
11-
11+
/******/
12+
}
1213
/******/ // Create a new module (and put it into the cache)
1314
/******/ var module = installedModules[moduleId] = {
14-
/******/ exports: {},
15-
/******/ id: moduleId,
16-
/******/ loaded: false
15+
/******/ i: moduleId,
16+
/******/ l: false,
17+
/******/ exports: {}
1718
/******/
18-
};
19-
19+
};
20+
/******/
2021
/******/ // Execute the module function
2122
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22-
23+
/******/
2324
/******/ // Flag the module as loaded
24-
/******/ module.loaded = true;
25-
25+
/******/ module.l = true;
26+
/******/
2627
/******/ // Return the exports of the module
2728
/******/ return module.exports;
2829
/******/
29-
}
30-
31-
30+
}
31+
/******/
32+
/******/
3233
/******/ // expose the modules object (__webpack_modules__)
3334
/******/ __webpack_require__.m = modules;
34-
35+
/******/
3536
/******/ // expose the module cache
3637
/******/ __webpack_require__.c = installedModules;
37-
38+
/******/
39+
/******/ // define getter function for harmony exports
40+
/******/ __webpack_require__.d = function (exports, name, getter) {
41+
/******/ if (!__webpack_require__.o(exports, name)) {
42+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
43+
/******/
44+
}
45+
/******/
46+
};
47+
/******/
48+
/******/ // define __esModule on exports
49+
/******/ __webpack_require__.r = function (exports) {
50+
/******/ if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
51+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
52+
/******/
53+
}
54+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
55+
/******/
56+
};
57+
/******/
58+
/******/ // create a fake namespace object
59+
/******/ // mode & 1: value is a module id, require it
60+
/******/ // mode & 2: merge all properties of value into the ns
61+
/******/ // mode & 4: return value when already ns object
62+
/******/ // mode & 8|1: behave like require
63+
/******/ __webpack_require__.t = function (value, mode) {
64+
/******/ if (mode & 1) value = __webpack_require__(value);
65+
/******/ if (mode & 8) return value;
66+
/******/ if ((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
67+
/******/ var ns = Object.create(null);
68+
/******/ __webpack_require__.r(ns);
69+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
70+
/******/ if (mode & 2 && typeof value != 'string') for (var key in value) __webpack_require__.d(ns, key, function (key) { return value[key]; }.bind(null, key));
71+
/******/ return ns;
72+
/******/
73+
};
74+
/******/
75+
/******/ // getDefaultExport function for compatibility with non-harmony modules
76+
/******/ __webpack_require__.n = function (module) {
77+
/******/ var getter = module && module.__esModule ?
78+
/******/ function getDefault() { return module['default']; } :
79+
/******/ function getModuleExports() { return module; };
80+
/******/ __webpack_require__.d(getter, 'a', getter);
81+
/******/ return getter;
82+
/******/
83+
};
84+
/******/
85+
/******/ // Object.prototype.hasOwnProperty.call
86+
/******/ __webpack_require__.o = function (object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
87+
/******/
3888
/******/ // __webpack_public_path__
3989
/******/ __webpack_require__.p = "";
40-
90+
/******/
91+
/******/
4192
/******/ // Load entry module and return exports
42-
/******/ return __webpack_require__(0);
93+
/******/ return __webpack_require__(__webpack_require__.s = 0);
4394
/******/
4495
})
4596
/************************************************************************/
4697
/******/([
4798
/* 0 */
48-
/***/ function (module, exports, __webpack_require__) {
99+
/***/ (function (module, exports, __webpack_require__) {
49100

50101
module.exports = __webpack_require__(1);
51102

52103

53104
/***/
54-
},
105+
}),
55106
/* 1 */
56-
/***/ function (module, exports, __webpack_require__) {
107+
/***/ (function (module, exports, __webpack_require__) {
57108

58109
"use strict";
110+
111+
exports.__esModule = true;
59112
// Limit dependencies to core Node modules. This means the code in this file has to be very low-level and unattractive,
60113
// but simplifies things for the consumer of this module.
61114
__webpack_require__(2);
@@ -119,13 +172,13 @@
119172
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
120173
var listenAddress = (useWindowsNamedPipes ? '\\\\.\\pipe\\' : '/tmp/') + parsedArgs.listenAddress;
121174
server.listen(listenAddress);
122-
ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid));
175+
ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid), /* ignoreSigint */ true);
123176

124177

125178
/***/
126-
},
179+
}),
127180
/* 2 */
128-
/***/ function (module, exports) {
181+
/***/ (function (module, exports) {
129182

130183
// When Node writes to stdout/strerr, we capture that and convert the lines into calls on the
131184
// active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing
@@ -165,32 +218,34 @@
165218

166219

167220
/***/
168-
},
221+
}),
169222
/* 3 */
170-
/***/ function (module, exports) {
223+
/***/ (function (module, exports) {
171224

172225
module.exports = require("net");
173226

174227
/***/
175-
},
228+
}),
176229
/* 4 */
177-
/***/ function (module, exports) {
230+
/***/ (function (module, exports) {
178231

179232
module.exports = require("path");
180233

181234
/***/
182-
},
235+
}),
183236
/* 5 */
184-
/***/ function (module, exports) {
237+
/***/ (function (module, exports) {
185238

186239
module.exports = require("readline");
187240

188241
/***/
189-
},
242+
}),
190243
/* 6 */
191-
/***/ function (module, exports) {
244+
/***/ (function (module, exports, __webpack_require__) {
192245

193246
"use strict";
247+
248+
exports.__esModule = true;
194249
function parseArgs(args) {
195250
// Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external
196251
// dependencies (such as an args-parsing library) to this file.
@@ -213,22 +268,24 @@
213268

214269

215270
/***/
216-
},
271+
}),
217272
/* 7 */
218-
/***/ function (module, exports) {
273+
/***/ (function (module, exports, __webpack_require__) {
274+
275+
"use strict";
219276

220277
/*
221278
In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
222279
because we have no further use for them. If the .NET process shuts down gracefully, it will run its
223280
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
224-
281+
225282
But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have
226283
any opportunity to shut down its child processes, and by default they will keep running. In this case, it's
227284
up to the child process to detect this has happened and terminate itself.
228-
285+
229286
There are many possible approaches to detecting when a parent process has exited, most of which behave
230287
differently between Windows and Linux/OS X:
231-
288+
232289
- On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when
233290
the parent does (http://stackoverflow.com/a/4657392). Not cross-platform.
234291
- The child Node process can get a callback when the parent disconnects (process.on('disconnect', ...)).
@@ -246,20 +303,38 @@
246303
However I don't see this documented anywhere. It would be nice if you could just poll for whether or not
247304
process.stdout is still connected (without actually writing to it) but I haven't found any property whose
248305
value changes until you actually try to write to it.
249-
306+
250307
Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling
251308
to check whether the parent PID is still running. So that's what we do here.
252309
*/
253-
"use strict";
310+
exports.__esModule = true;
254311
var pollIntervalMs = 1000;
255-
function exitWhenParentExits(parentPid) {
312+
function exitWhenParentExits(parentPid, ignoreSigint) {
256313
setInterval(function () {
257314
if (!processExists(parentPid)) {
258315
// Can't log anything at this point, because out stdout was connected to the parent,
259316
// but the parent is gone.
260317
process.exit();
261318
}
262319
}, pollIntervalMs);
320+
if (ignoreSigint) {
321+
// Pressing ctrl+c in the terminal sends a SIGINT to all processes in the foreground process tree.
322+
// By default, the Node process would then exit before the .NET process, because ASP.NET implements
323+
// a delayed shutdown to allow ongoing requests to complete.
324+
//
325+
// This is problematic, because if Node exits first, the CopyToAsync code in ConditionalProxyMiddleware
326+
// will experience a read fault, and logs a huge load of errors. Fortunately, since the Node process is
327+
// already set up to shut itself down if it detects the .NET process is terminated, all we have to do is
328+
// ignore the SIGINT. The Node process will then terminate automatically after the .NET process does.
329+
//
330+
// A better solution would be to have WebpackDevMiddleware listen for SIGINT and gracefully close any
331+
// ongoing EventSource connections before letting the Node process exit, independently of the .NET
332+
// process exiting. However, doing this well in general is very nontrivial (see all the discussion at
333+
// https://github.com/nodejs/node/issues/2642).
334+
process.on('SIGINT', function () {
335+
console.log('Received SIGINT. Waiting for .NET process to exit...');
336+
});
337+
}
263338
}
264339
exports.exitWhenParentExits = exitWhenParentExits;
265340
function processExists(pid) {
@@ -281,11 +356,13 @@
281356

282357

283358
/***/
284-
},
359+
}),
285360
/* 8 */
286-
/***/ function (module, exports, __webpack_require__) {
361+
/***/ (function (module, exports, __webpack_require__) {
287362

288363
"use strict";
364+
365+
exports.__esModule = true;
289366
var events_1 = __webpack_require__(9);
290367
var VirtualConnection_1 = __webpack_require__(10);
291368
// Keep this in sync with the equivalent constant in the .NET code. Both sides split up their transmissions into frames with this max length,
@@ -311,7 +388,7 @@
311388
/**
312389
* Tracks the 'virtual connections' associated with a single physical socket connection.
313390
*/
314-
var VirtualConnectionsCollection = (function () {
391+
var VirtualConnectionsCollection = /** @class */ (function () {
315392
function VirtualConnectionsCollection(_socket, _onVirtualConnectionCallback) {
316393
var _this = this;
317394
this._socket = _socket;
@@ -393,7 +470,7 @@
393470
newVirtualConnection.on('finish', function () {
394471
// The virtual connection was closed locally. Clean up locally, and notify the remote that we're done.
395472
_this._onVirtualConnectionWasClosed(header.connectionIdString);
396-
_this._sendFrame(header.connectionIdBinary, Buffer.alloc(0));
473+
_this._sendFrame(header.connectionIdBinary, new Buffer(0));
397474
});
398475
this._virtualConnections[header.connectionIdString] = newVirtualConnection;
399476
this._onVirtualConnectionCallback(newVirtualConnection);
@@ -455,7 +532,7 @@
455532
* Sends a number serialized in the correct format for .NET to receive as a System.Int32
456533
*/
457534
VirtualConnectionsCollection.prototype._sendInt32LE = function (value, callback) {
458-
var buf = Buffer.alloc(4);
535+
var buf = new Buffer(4);
459536
buf.writeInt32LE(value, 0);
460537
this._socket.write(buf, callback);
461538
};
@@ -469,28 +546,38 @@
469546

470547

471548
/***/
472-
},
549+
}),
473550
/* 9 */
474-
/***/ function (module, exports) {
551+
/***/ (function (module, exports) {
475552

476553
module.exports = require("events");
477554

478555
/***/
479-
},
556+
}),
480557
/* 10 */
481-
/***/ function (module, exports, __webpack_require__) {
558+
/***/ (function (module, exports, __webpack_require__) {
482559

483560
"use strict";
484-
var __extends = (this && this.__extends) || function (d, b) {
485-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
486-
function __() { this.constructor = d; }
487-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
488-
};
561+
562+
var __extends = (this && this.__extends) || (function () {
563+
var extendStatics = function (d, b) {
564+
extendStatics = Object.setPrototypeOf ||
565+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
566+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
567+
return extendStatics(d, b);
568+
}
569+
return function (d, b) {
570+
extendStatics(d, b);
571+
function __() { this.constructor = d; }
572+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
573+
};
574+
})();
575+
exports.__esModule = true;
489576
var stream_1 = __webpack_require__(11);
490577
/**
491578
* Represents a virtual connection. Multiple virtual connections may be multiplexed over a single physical socket connection.
492579
*/
493-
var VirtualConnection = (function (_super) {
580+
var VirtualConnection = /** @class */ (function (_super) {
494581
__extends(VirtualConnection, _super);
495582
function VirtualConnection(_beginWriteCallback) {
496583
var _this = _super.call(this) || this;
@@ -510,7 +597,7 @@
510597
};
511598
VirtualConnection.prototype._write = function (chunk, encodingIfString, callback) {
512599
if (typeof chunk === 'string') {
513-
chunk = Buffer.from(chunk, encodingIfString);
600+
chunk = new Buffer(chunk, encodingIfString);
514601
}
515602
this._beginWriteCallback(chunk, callback);
516603
};
@@ -528,12 +615,12 @@
528615

529616

530617
/***/
531-
},
618+
}),
532619
/* 11 */
533-
/***/ function (module, exports) {
620+
/***/ (function (module, exports) {
534621

535622
module.exports = require("stream");
536623

537624
/***/
538-
}
625+
})
539626
/******/])));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.