You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

486 lines
14 KiB

Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
  1. import os from 'os';
  2. import throng from 'throng';
  3. import dotenv from 'dotenv';
  4. import express from 'express';
  5. import http from 'http';
  6. import redis from 'redis';
  7. import pg from 'pg';
  8. import log from 'npmlog';
  9. import url from 'url';
  10. import WebSocket from 'uws';
  11. import uuid from 'uuid';
  12. const env = process.env.NODE_ENV || 'development';
  13. dotenv.config({
  14. path: env === 'production' ? '.env.production' : '.env',
  15. });
  16. log.level = process.env.LOG_LEVEL || 'verbose';
  17. const dbUrlToConfig = (dbUrl) => {
  18. if (!dbUrl) {
  19. return {};
  20. }
  21. const params = url.parse(dbUrl);
  22. const config = {};
  23. if (params.auth) {
  24. [config.user, config.password] = params.auth.split(':');
  25. }
  26. if (params.hostname) {
  27. config.host = params.hostname;
  28. }
  29. if (params.port) {
  30. config.port = params.port;
  31. }
  32. if (params.pathname) {
  33. config.database = params.pathname.split('/')[1];
  34. }
  35. const ssl = params.query && params.query.ssl;
  36. if (ssl) {
  37. config.ssl = ssl === 'true' || ssl === '1';
  38. }
  39. return config;
  40. };
  41. const redisUrlToClient = (defaultConfig, redisUrl) => {
  42. const config = defaultConfig;
  43. if (!redisUrl) {
  44. return redis.createClient(config);
  45. }
  46. if (redisUrl.startsWith('unix://')) {
  47. return redis.createClient(redisUrl.slice(7), config);
  48. }
  49. return redis.createClient(Object.assign(config, {
  50. url: redisUrl,
  51. }));
  52. };
  53. const numWorkers = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : Math.max(os.cpus().length - 1, 1));
  54. const startMaster = () => {
  55. log.info(`Starting streaming API server master with ${numWorkers} workers`);
  56. };
  57. const startWorker = (workerId) => {
  58. log.info(`Starting worker ${workerId}`);
  59. const pgConfigs = {
  60. development: {
  61. user: process.env.DB_USER || pg.defaults.user,
  62. password: process.env.DB_PASS || pg.defaults.password,
  63. database: 'mastodon_development',
  64. host: process.env.DB_HOST || pg.defaults.host,
  65. port: process.env.DB_PORT || pg.defaults.port,
  66. max: 10,
  67. },
  68. production: {
  69. user: process.env.DB_USER || 'mastodon',
  70. password: process.env.DB_PASS || '',
  71. database: process.env.DB_NAME || 'mastodon_production',
  72. host: process.env.DB_HOST || 'localhost',
  73. port: process.env.DB_PORT || 5432,
  74. max: 10,
  75. },
  76. };
  77. const app = express();
  78. const pgPool = new pg.Pool(Object.assign(pgConfigs[env], dbUrlToConfig(process.env.DATABASE_URL)));
  79. const server = http.createServer(app);
  80. const redisNamespace = process.env.REDIS_NAMESPACE || null;
  81. const redisParams = {
  82. host: process.env.REDIS_HOST || '127.0.0.1',
  83. port: process.env.REDIS_PORT || 6379,
  84. db: process.env.REDIS_DB || 0,
  85. password: process.env.REDIS_PASSWORD,
  86. };
  87. if (redisNamespace) {
  88. redisParams.namespace = redisNamespace;
  89. }
  90. const redisPrefix = redisNamespace ? `${redisNamespace}:` : '';
  91. const redisSubscribeClient = redisUrlToClient(redisParams, process.env.REDIS_URL);
  92. const redisClient = redisUrlToClient(redisParams, process.env.REDIS_URL);
  93. const subs = {};
  94. redisSubscribeClient.on('message', (channel, message) => {
  95. const callbacks = subs[channel];
  96. log.silly(`New message on channel ${channel}`);
  97. if (!callbacks) {
  98. return;
  99. }
  100. callbacks.forEach(callback => callback(message));
  101. });
  102. const subscriptionHeartbeat = (channel) => {
  103. const interval = 6*60;
  104. const tellSubscribed = () => {
  105. redisClient.set(`${redisPrefix}subscribed:${channel}`, '1', 'EX', interval*3);
  106. };
  107. tellSubscribed();
  108. const heartbeat = setInterval(tellSubscribed, interval*1000);
  109. return () => {
  110. clearInterval(heartbeat);
  111. };
  112. };
  113. const subscribe = (channel, callback) => {
  114. log.silly(`Adding listener for ${channel}`);
  115. subs[channel] = subs[channel] || [];
  116. if (subs[channel].length === 0) {
  117. log.verbose(`Subscribe ${channel}`);
  118. redisSubscribeClient.subscribe(channel);
  119. }
  120. subs[channel].push(callback);
  121. };
  122. const unsubscribe = (channel, callback) => {
  123. log.silly(`Removing listener for ${channel}`);
  124. subs[channel] = subs[channel].filter(item => item !== callback);
  125. if (subs[channel].length === 0) {
  126. log.verbose(`Unsubscribe ${channel}`);
  127. redisSubscribeClient.unsubscribe(channel);
  128. }
  129. };
  130. const allowCrossDomain = (req, res, next) => {
  131. res.header('Access-Control-Allow-Origin', '*');
  132. res.header('Access-Control-Allow-Headers', 'Authorization, Accept, Cache-Control');
  133. res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
  134. next();
  135. };
  136. const setRequestId = (req, res, next) => {
  137. req.requestId = uuid.v4();
  138. res.header('X-Request-Id', req.requestId);
  139. next();
  140. };
  141. const accountFromToken = (token, req, next) => {
  142. pgPool.connect((err, client, done) => {
  143. if (err) {
  144. next(err);
  145. return;
  146. }
  147. client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id, users.filtered_languages FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE oauth_access_tokens.token = $1 AND oauth_access_tokens.revoked_at IS NULL LIMIT 1', [token], (err, result) => {
  148. done();
  149. if (err) {
  150. next(err);
  151. return;
  152. }
  153. if (result.rows.length === 0) {
  154. err = new Error('Invalid access token');
  155. err.statusCode = 401;
  156. next(err);
  157. return;
  158. }
  159. req.accountId = result.rows[0].account_id;
  160. req.filteredLanguages = result.rows[0].filtered_languages;
  161. next();
  162. });
  163. });
  164. };
  165. const accountFromRequest = (req, next) => {
  166. const authorization = req.headers.authorization;
  167. const location = url.parse(req.url, true);
  168. const accessToken = location.query.access_token;
  169. if (!authorization && !accessToken) {
  170. const err = new Error('Missing access token');
  171. err.statusCode = 401;
  172. next(err);
  173. return;
  174. }
  175. const token = authorization ? authorization.replace(/^Bearer /, '') : accessToken;
  176. accountFromToken(token, req, next);
  177. };
  178. const wsVerifyClient = (info, cb) => {
  179. accountFromRequest(info.req, err => {
  180. if (!err) {
  181. cb(true, undefined, undefined);
  182. } else {
  183. log.error(info.req.requestId, err.toString());
  184. cb(false, 401, 'Unauthorized');
  185. }
  186. });
  187. };
  188. const authenticationMiddleware = (req, res, next) => {
  189. if (req.method === 'OPTIONS') {
  190. next();
  191. return;
  192. }
  193. accountFromRequest(req, next);
  194. };
  195. const errorMiddleware = (err, req, res, {}) => {
  196. log.error(req.requestId, err.toString());
  197. res.writeHead(err.statusCode || 500, { 'Content-Type': 'application/json' });
  198. res.end(JSON.stringify({ error: err.statusCode ? err.toString() : 'An unexpected error occurred' }));
  199. };
  200. const placeholders = (arr, shift = 0) => arr.map((_, i) => `$${i + 1 + shift}`).join(', ');
  201. const streamFrom = (id, req, output, attachCloseHandler, needsFiltering = false, notificationOnly = false) => {
  202. const streamType = notificationOnly ? ' (notification)' : '';
  203. log.verbose(req.requestId, `Starting stream from ${id} for ${req.accountId}${streamType}`);
  204. const listener = message => {
  205. const { event, payload, queued_at } = JSON.parse(message);
  206. const transmit = () => {
  207. const now = new Date().getTime();
  208. const delta = now - queued_at;
  209. log.silly(req.requestId, `Transmitting for ${req.accountId}: ${event} ${payload} Delay: ${delta}ms`);
  210. output(event, payload);
  211. };
  212. if (notificationOnly && event !== 'notification') {
  213. return;
  214. }
  215. // Only messages that may require filtering are statuses, since notifications
  216. // are already personalized and deletes do not matter
  217. if (needsFiltering && event === 'update') {
  218. pgPool.connect((err, client, done) => {
  219. if (err) {
  220. log.error(err);
  221. return;
  222. }
  223. const unpackedPayload = JSON.parse(payload);
  224. const targetAccountIds = [unpackedPayload.account.id].concat(unpackedPayload.mentions.map(item => item.id));
  225. const accountDomain = unpackedPayload.account.acct.split('@')[1];
  226. if (Array.isArray(req.filteredLanguages) && req.filteredLanguages.indexOf(unpackedPayload.language) !== -1) {
  227. log.silly(req.requestId, `Message ${unpackedPayload.id} filtered by language (${unpackedPayload.language})`);
  228. done();
  229. return;
  230. }
  231. const queries = [
  232. client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})`, [req.accountId, unpackedPayload.account.id].concat(targetAccountIds)),
  233. ];
  234. if (accountDomain) {
  235. queries.push(client.query('SELECT 1 FROM account_domain_blocks WHERE account_id = $1 AND domain = $2', [req.accountId, accountDomain]));
  236. }
  237. Promise.all(queries).then(values => {
  238. done();
  239. if (values[0].rows.length > 0 || (values.length > 1 && values[1].rows.length > 0)) {
  240. return;
  241. }
  242. transmit();
  243. }).catch(err => {
  244. done();
  245. log.error(err);
  246. });
  247. });
  248. } else {
  249. transmit();
  250. }
  251. };
  252. subscribe(`${redisPrefix}${id}`, listener);
  253. attachCloseHandler(`${redisPrefix}${id}`, listener);
  254. };
  255. // Setup stream output to HTTP
  256. const streamToHttp = (req, res) => {
  257. res.setHeader('Content-Type', 'text/event-stream');
  258. res.setHeader('Transfer-Encoding', 'chunked');
  259. const heartbeat = setInterval(() => res.write(':thump\n'), 15000);
  260. req.on('close', () => {
  261. log.verbose(req.requestId, `Ending stream for ${req.accountId}`);
  262. clearInterval(heartbeat);
  263. });
  264. return (event, payload) => {
  265. res.write(`event: ${event}\n`);
  266. res.write(`data: ${payload}\n\n`);
  267. };
  268. };
  269. // Setup stream end for HTTP
  270. const streamHttpEnd = (req, closeHandler = false) => (id, listener) => {
  271. req.on('close', () => {
  272. unsubscribe(id, listener);
  273. if (closeHandler) {
  274. closeHandler();
  275. }
  276. });
  277. };
  278. // Setup stream output to WebSockets
  279. const streamToWs = (req, ws) => (event, payload) => {
  280. if (ws.readyState !== ws.OPEN) {
  281. log.error(req.requestId, 'Tried writing to closed socket');
  282. return;
  283. }
  284. ws.send(JSON.stringify({ event, payload }));
  285. };
  286. // Setup stream end for WebSockets
  287. const streamWsEnd = (req, ws, closeHandler = false) => (id, listener) => {
  288. ws.on('close', () => {
  289. log.verbose(req.requestId, `Ending stream for ${req.accountId}`);
  290. unsubscribe(id, listener);
  291. if (closeHandler) {
  292. closeHandler();
  293. }
  294. });
  295. ws.on('error', () => {
  296. log.verbose(req.requestId, `Ending stream for ${req.accountId}`);
  297. unsubscribe(id, listener);
  298. if (closeHandler) {
  299. closeHandler();
  300. }
  301. });
  302. };
  303. app.use(setRequestId);
  304. app.use(allowCrossDomain);
  305. app.use(authenticationMiddleware);
  306. app.use(errorMiddleware);
  307. app.get('/api/v1/streaming/user', (req, res) => {
  308. const channel = `timeline:${req.accountId}`;
  309. streamFrom(channel, req, streamToHttp(req, res), streamHttpEnd(req, subscriptionHeartbeat(channel)));
  310. });
  311. app.get('/api/v1/streaming/user/notification', (req, res) => {
  312. streamFrom(`timeline:${req.accountId}`, req, streamToHttp(req, res), streamHttpEnd(req), false, true);
  313. });
  314. app.get('/api/v1/streaming/public', (req, res) => {
  315. streamFrom('timeline:public', req, streamToHttp(req, res), streamHttpEnd(req), true);
  316. });
  317. app.get('/api/v1/streaming/public/local', (req, res) => {
  318. streamFrom('timeline:public:local', req, streamToHttp(req, res), streamHttpEnd(req), true);
  319. });
  320. app.get('/api/v1/streaming/hashtag', (req, res) => {
  321. streamFrom(`timeline:hashtag:${req.query.tag}`, req, streamToHttp(req, res), streamHttpEnd(req), true);
  322. });
  323. app.get('/api/v1/streaming/hashtag/local', (req, res) => {
  324. streamFrom(`timeline:hashtag:${req.query.tag}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true);
  325. });
  326. const wss = new WebSocket.Server({ server, verifyClient: wsVerifyClient });
  327. wss.on('connection', ws => {
  328. const req = ws.upgradeReq;
  329. const location = url.parse(req.url, true);
  330. req.requestId = uuid.v4();
  331. ws.isAlive = true;
  332. ws.on('pong', () => {
  333. ws.isAlive = true;
  334. });
  335. switch(location.query.stream) {
  336. case 'user':
  337. const channel = `timeline:${req.accountId}`;
  338. streamFrom(channel, req, streamToWs(req, ws), streamWsEnd(req, ws, subscriptionHeartbeat(channel)));
  339. break;
  340. case 'user:notification':
  341. streamFrom(`timeline:${req.accountId}`, req, streamToWs(req, ws), streamWsEnd(req, ws), false, true);
  342. break;
  343. case 'public':
  344. streamFrom('timeline:public', req, streamToWs(req, ws), streamWsEnd(req, ws), true);
  345. break;
  346. case 'public:local':
  347. streamFrom('timeline:public:local', req, streamToWs(req, ws), streamWsEnd(req, ws), true);
  348. break;
  349. case 'hashtag':
  350. streamFrom(`timeline:hashtag:${location.query.tag}`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
  351. break;
  352. case 'hashtag:local':
  353. streamFrom(`timeline:hashtag:${location.query.tag}:local`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
  354. break;
  355. default:
  356. ws.close();
  357. }
  358. });
  359. setInterval(() => {
  360. wss.clients.forEach(ws => {
  361. if (ws.isAlive === false) {
  362. ws.terminate();
  363. return;
  364. }
  365. ws.isAlive = false;
  366. ws.ping('', false, true);
  367. });
  368. }, 30000);
  369. server.listen(process.env.PORT || 4000, () => {
  370. log.info(`Worker ${workerId} now listening on ${server.address().address}:${server.address().port}`);
  371. });
  372. const onExit = () => {
  373. log.info(`Worker ${workerId} exiting, bye bye`);
  374. server.close();
  375. };
  376. const onError = (err) => {
  377. log.error(err);
  378. };
  379. process.on('SIGINT', onExit);
  380. process.on('SIGTERM', onExit);
  381. process.on('exit', onExit);
  382. process.on('error', onError);
  383. };
  384. throng({
  385. workers: numWorkers,
  386. lifetime: Infinity,
  387. start: startWorker,
  388. master: startMaster,
  389. });