From 22f4dd3fb729b2faa473c43d90edbfd0b3cc3083 Mon Sep 17 00:00:00 2001 From: b-ma Date: Thu, 23 May 2024 17:03:50 +0200 Subject: [PATCH] fix: do not terminate socket on handshake error, triggers an annoying reload on dev --- src/client/Client.js | 9 +++++---- src/server/Server.js | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index a23d9cde..e7dd14c3 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -276,11 +276,12 @@ dependancies on both your server and clients. msg = `[soundworks:Client] ${err.message}`; break; default: - msg = `Undefined error`; + msg = `[soundworks:Client] Undefined error: ${err.message}`; break; } - this.socket[kSocketTerminate](); + // These are development errors, we can just hang. If we terminate the + // socket, a reload is triggered by the launcher which is bad in terms of DX reject(msg); }); @@ -293,8 +294,8 @@ dependancies on both your server and clients. this.socket.send(CLIENT_HANDSHAKE_REQUEST, payload); }); - } catch (err) { - throw new Error(err); + } catch (msg) { + throw new Error(msg); } // ------------------------------------------------------------ diff --git a/src/server/Server.js b/src/server/Server.js index d416aace..250923e7 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -4,9 +4,16 @@ import http from 'node:http'; import https from 'node:https'; import path from 'node:path'; import os from 'node:os'; -import { X509Certificate, createPrivateKey } from 'node:crypto'; +import { + X509Certificate, + createPrivateKey, +} from 'node:crypto'; -import { isPlainObject, idGenerator, getTime } from '@ircam/sc-utils'; +import { + isPlainObject, + idGenerator, + getTime, +} from '@ircam/sc-utils'; import chalk from 'chalk'; import compression from 'compression'; import express from 'express'; @@ -18,7 +25,10 @@ import pem from 'pem'; import compile from 'template-literal'; import auditSchema from './audit-schema.js'; -import { encryptData, decryptData } from './crypto.js'; +import { + encryptData, + decryptData, +} from './crypto.js'; import Client from './Client.js'; import ContextManager from './ContextManager.js'; import PluginManager from './PluginManager.js'; @@ -678,7 +688,7 @@ Invalid certificate files, please check your: // this.httpsInfos.isValid = false; // for testing if (!this.httpsInfos.isValid) { logger.error(chalk.red` -------------------------------------------`); - logger.error(chalk.red` > INVALID CERTIFICATE`); + logger.error(chalk.red` > INVALID CERTIFICATE `); logger.error(chalk.red` i.e. you pretend to be safe but you are not`); logger.error(chalk.red` -------------------------------------------`); } else {