| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1e57c67 commit f3ba1eb
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1121,6 +1121,26 @@ Emitted when a new TCP or pipe client socket is created. | |||
| 1121 | 1121 | ||
| 1122 | 1122 | Emitted when a new TCP or pipe connection is received. | |
| 1123 | 1123 | ||
| 1124 | + `tracing:net.server.listen:asyncStart` | ||
| 1125 | + | ||
| 1126 | + * `server` {net.Server} | ||
| 1127 | + * `options` {Object} | ||
| 1128 | + | ||
| 1129 | + Emitted when [`net.Server.listen()`][] is invoked, before the port or pipe is actually setup. | ||
| 1130 | + | ||
| 1131 | + `tracing:net.server.listen:asyncEnd` | ||
| 1132 | + | ||
| 1133 | + * `server` {net.Server} | ||
| 1134 | + | ||
| 1135 | + Emitted when [`net.Server.listen()`][] has completed and thus the server is ready to accept connection. | ||
| 1136 | + | ||
| 1137 | + `tracing:net.server.listen:error` | ||
| 1138 | + | ||
| 1139 | + * `server` {net.Server} | ||
| 1140 | + * `error` {Error} | ||
| 1141 | + | ||
| 1142 | + Emitted when [`net.Server.listen()`][] is returning an error. | ||
| 1143 | + | ||
| 1124 | 1144 | #### UDP | |
| 1125 | 1145 | ||
| 1126 | 1146 | `udp.socket` | |
@@ -1169,5 +1189,6 @@ Emitted when a new thread is created. | |||
| 1169 | 1189 | [`diagnostics_channel.unsubscribe(name, onMessage)`]: #diagnostics_channelunsubscribename-onmessage | |
| 1170 | 1190 | [`end` event]: #endevent | |
| 1171 | 1191 | [`error` event]: #errorevent | |
| 1192 | + [`net.Server.listen()`]: net.md#serverlisten | ||
| 1172 | 1193 | [`start` event]: #startevent | |
| 1173 | 1194 | [context loss]: async_context.md#troubleshooting-context-loss | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -151,6 +151,7 @@ const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext'); | |||
| 151 | 151 | const dc = require('diagnostics_channel'); | |
| 152 | 152 | const netClientSocketChannel = dc.channel('net.client.socket'); | |
| 153 | 153 | const netServerSocketChannel = dc.channel('net.server.socket'); | |
| 154 | + const netServerListen = dc.tracingChannel('net.server.listen'); | ||
| 154 | 155 | ||
| 155 | 156 | const { | |
| 156 | 157 | hasObserver, | |
@@ -1879,6 +1880,11 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) { | |||
| 1879 | 1880 | ||
| 1880 | 1881 | if (typeof rval === 'number') { | |
| 1881 | 1882 | const error = new UVExceptionWithHostPort(rval, 'listen', address, port); | |
| 1883 | + | ||
| 1884 | + if (netServerListen.hasSubscribers) { | ||
| 1885 | + netServerListen.error.publish({ server: this, error }); | ||
| 1886 | + } | ||
| 1887 | + | ||
| 1882 | 1888 | process.nextTick(emitErrorNT, this, error); | |
| 1883 | 1889 | return; | |
| 1884 | 1890 | } | |
@@ -1898,6 +1904,11 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) { | |||
| 1898 | 1904 | const ex = new UVExceptionWithHostPort(err, 'listen', address, port); | |
| 1899 | 1905 | this._handle.close(); | |
| 1900 | 1906 | this._handle = null; | |
| 1907 | + | ||
| 1908 | + if (netServerListen.hasSubscribers) { | ||
| 1909 | + netServerListen.error.publish({ server: this, error: ex }); | ||
| 1910 | + } | ||
| 1911 | + | ||
| 1901 | 1912 | defaultTriggerAsyncIdScope(this[async_id_symbol], | |
| 1902 | 1913 | process.nextTick, | |
| 1903 | 1914 | emitErrorNT, | |
@@ -1906,6 +1917,10 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) { | |||
| 1906 | 1917 | return; | |
| 1907 | 1918 | } | |
| 1908 | 1919 | ||
| 1920 | + if (netServerListen.hasSubscribers) { | ||
| 1921 | + netServerListen.asyncEnd.publish({ server: this }); | ||
| 1922 | + } | ||
| 1923 | + | ||
| 1909 | 1924 | // Generate connection key, this should be unique to the connection | |
| 1910 | 1925 | this._connectionKey = addressType + ':' + address + ':' + port; | |
| 1911 | 1926 | ||
@@ -1993,6 +2008,10 @@ Server.prototype.listen = function(...args) { | |||
| 1993 | 2008 | throw new ERR_SERVER_ALREADY_LISTEN(); | |
| 1994 | 2009 | } | |
| 1995 | 2010 | ||
| 2011 | + if (netServerListen.hasSubscribers) { | ||
| 2012 | + netServerListen.asyncStart.publish({ server: this, options }); | ||
| 2013 | + } | ||
| 2014 | + | ||
| 1996 | 2015 | if (cb !== null) { | |
| 1997 | 2016 | this.once('listening', cb); | |
| 1998 | 2017 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,21 +5,87 @@ const net = require('net'); | |||
| 5 | 5 | const dc = require('diagnostics_channel'); | |
| 6 | 6 | ||
| 7 | 7 | const isNetSocket = (socket) => socket instanceof net.Socket; | |
| 8 | + const isNetServer = (server) => server instanceof net.Server; | ||
| 8 | 9 | ||
| 9 | - dc.subscribe('net.client.socket', common.mustCall(({ socket }) => { | ||
| 10 | - assert.strictEqual(isNetSocket(socket), true); | ||
| 11 | - })); | ||
| 10 | + function testDiagnosticChannel(subscribers, test, after) { | ||
| 11 | + dc.tracingChannel('net.server.listen').subscribe(subscribers); | ||
| 12 | 12 | ||
| 13 | - dc.subscribe('net.server.socket', common.mustCall(({ socket }) => { | ||
| 14 | - assert.strictEqual(isNetSocket(socket), true); | ||
| 15 | - })); | ||
| 13 | + test(common.mustCall(() => { | ||
| 14 | + dc.tracingChannel('net.server.listen').unsubscribe(subscribers); | ||
| 15 | + after?.(); | ||
| 16 | + })); | ||
| 17 | + } | ||
| 16 | 18 | ||
| 17 | - const server = net.createServer(common.mustCall((socket) => { | ||
| 18 | - socket.destroy(); | ||
| 19 | - server.close(); | ||
| 20 | - })); | ||
| 19 | + const testSuccessfullListen = common.mustCall(() => { | ||
| 20 | + let cb; | ||
| 21 | + const server = net.createServer(common.mustCall((socket) => { | ||
| 22 | + socket.destroy(); | ||
| 23 | + server.close(); | ||
| 24 | + cb(); | ||
| 25 | + })); | ||
| 21 | 26 | ||
| 22 | - server.listen(() => { | ||
| 23 | - const { port } = server.address(); | ||
| 24 | - net.connect(port); | ||
| 27 | + dc.subscribe('net.client.socket', common.mustCall(({ socket }) => { | ||
| 28 | + assert.strictEqual(isNetSocket(socket), true); | ||
| 29 | + })); | ||
| 30 | + | ||
| 31 | + dc.subscribe('net.server.socket', common.mustCall(({ socket }) => { | ||
| 32 | + assert.strictEqual(isNetSocket(socket), true); | ||
| 33 | + })); | ||
| 34 | + | ||
| 35 | + testDiagnosticChannel( | ||
| 36 | + { | ||
| 37 | + asyncStart: common.mustCall(({ server: currentServer, options }) => { | ||
| 38 | + assert.strictEqual(isNetServer(server), true); | ||
| 39 | + assert.strictEqual(currentServer, server); | ||
| 40 | + assert.strictEqual(options.customOption, true); | ||
| 41 | + }), | ||
| 42 | + asyncEnd: common.mustCall(({ server: currentServer }) => { | ||
| 43 | + assert.strictEqual(isNetServer(server), true); | ||
| 44 | + assert.strictEqual(currentServer, server); | ||
| 45 | + }), | ||
| 46 | + error: common.mustNotCall() | ||
| 47 | + }, | ||
| 48 | + common.mustCall((callback) => { | ||
| 49 | + cb = callback; | ||
| 50 | + server.listen({ port: 0, customOption: true }, () => { | ||
| 51 | + const { port } = server.address(); | ||
| 52 | + net.connect(port); | ||
| 53 | + }); | ||
| 54 | + }), | ||
| 55 | + testFailingListen | ||
| 56 | + ); | ||
| 25 | 57 | }); | |
| 58 | + | ||
| 59 | + const testFailingListen = common.mustCall(() => { | ||
| 60 | + const originalServer = net.createServer(common.mustNotCall()); | ||
| 61 | + | ||
| 62 | + originalServer.listen(() => { | ||
| 63 | + const server = net.createServer(common.mustNotCall()); | ||
| 64 | + | ||
| 65 | + testDiagnosticChannel( | ||
| 66 | + { | ||
| 67 | + asyncStart: common.mustCall(({ server: currentServer, options }) => { | ||
| 68 | + assert.strictEqual(isNetServer(server), true); | ||
| 69 | + assert.strictEqual(currentServer, server); | ||
| 70 | + assert.strictEqual(options.customOption, true); | ||
| 71 | + }), | ||
| 72 | + asyncEnd: common.mustNotCall(), | ||
| 73 | + error: common.mustCall(({ server: currentServer }) => { | ||
| 74 | + assert.strictEqual(isNetServer(server), true); | ||
| 75 | + assert.strictEqual(currentServer, server); | ||
| 76 | + }), | ||
| 77 | + }, | ||
| 78 | + common.mustCall((callback) => { | ||
| 79 | + server.on('error', () => {}); | ||
| 80 | + server.listen({ port: originalServer.address().port, customOption: true }); | ||
| 81 | + callback(); | ||
| 82 | + }), | ||
| 83 | + common.mustCall(() => { | ||
| 84 | + originalServer.close(); | ||
| 85 | + server.close(); | ||
| 86 | + }) | ||
| 87 | + ); | ||
| 88 | + }); | ||
| 89 | + }); | ||
| 90 | + | ||
| 91 | + testSuccessfullListen(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments