Fix connection timeout being set incorrectly
This commit is contained in:
1 parent
9f4b421b59
commit
62849e8081
6 files changed
+69
-43
No files matched your search
+11
-5
@@ -840,8 +840,11 @@ async function sendAcsRequest(
|
||||
return writeResponse(sessionContext, res);
|
||||
}
|
||||
|
||||
async function getSession(connection, sessionId): Promise<SessionContext> {
|
||||
const sessionContext = currentSessions.get(connection);
|
||||
async function getSession(
|
||||
connection: Socket,
|
||||
sessionId: string
|
||||
): Promise<SessionContext> {
|
||||
let sessionContext = currentSessions.get(connection);
|
||||
if (sessionContext) {
|
||||
currentSessions.delete(connection);
|
||||
return sessionContext;
|
||||
@@ -853,7 +856,9 @@ async function getSession(connection, sessionId): Promise<SessionContext> {
|
||||
|
||||
const sessionContextString = await cache.pop(`session_${sessionId}`);
|
||||
if (!sessionContextString) return null;
|
||||
return session.deserialize(sessionContextString);
|
||||
sessionContext = await session.deserialize(sessionContextString);
|
||||
connection.setTimeout(sessionContext.timeout);
|
||||
return sessionContext;
|
||||
}
|
||||
|
||||
// Only needed to prevent tree shaking from removing the remoteAddress
|
||||
@@ -1068,6 +1073,8 @@ async function processRequest(
|
||||
);
|
||||
}
|
||||
|
||||
sessionContext.httpRequest.socket.setTimeout(sessionContext.timeout * 1000);
|
||||
|
||||
if (sessionContext.debug) {
|
||||
debug.incomingHttpRequest(
|
||||
sessionContext.httpRequest,
|
||||
@@ -1412,7 +1419,7 @@ async function listenerAsync(
|
||||
}
|
||||
|
||||
const parseWarnings = [];
|
||||
let rpc;
|
||||
let rpc: SoapMessage;
|
||||
try {
|
||||
rpc = soap.request(
|
||||
bodyStr,
|
||||
@@ -1517,7 +1524,6 @@ async function listenerAsync(
|
||||
_sessionContext.httpRequest = httpRequest;
|
||||
_sessionContext.httpResponse = httpResponse;
|
||||
_sessionContext.sessionId = crypto.randomBytes(8).toString("hex");
|
||||
httpRequest.socket.setTimeout(_sessionContext.timeout * 1000);
|
||||
|
||||
const {
|
||||
tasks: dueTasks,
|
||||
|
||||
+23
-15
@@ -52,35 +52,43 @@ function closeServer(timeout, callback): void {
|
||||
});
|
||||
}
|
||||
|
||||
interface ServerOptions {
|
||||
port?: number;
|
||||
host?: string;
|
||||
ssl?: { key: string; cert: string };
|
||||
timeout?: number;
|
||||
keepAliveTimeout?: number;
|
||||
onConnection?: (socket: Socket) => void;
|
||||
}
|
||||
|
||||
export function start(
|
||||
port: number,
|
||||
networkInterface: string,
|
||||
ssl: { key: string; cert: string },
|
||||
_listener: http.RequestListener,
|
||||
onConnection?: (socket: Socket) => void,
|
||||
keepAliveTimeout = -1
|
||||
options: ServerOptions,
|
||||
_listener: http.RequestListener
|
||||
): void {
|
||||
listener = _listener;
|
||||
|
||||
if (ssl && ssl.key && ssl.cert) {
|
||||
const options = {
|
||||
key: ssl.key
|
||||
if (options.ssl) {
|
||||
const opts = {
|
||||
key: options.ssl.key
|
||||
.split(":")
|
||||
.map((f) => fs.readFileSync(path.resolve(ROOT_DIR, f.trim()))),
|
||||
cert: ssl.cert
|
||||
cert: options.ssl.cert
|
||||
.split(":")
|
||||
.map((f) => fs.readFileSync(path.resolve(ROOT_DIR, f.trim()))),
|
||||
};
|
||||
|
||||
server = https.createServer(options, listener);
|
||||
if (onConnection != null) server.on("secureConnection", onConnection);
|
||||
server = https.createServer(opts, listener);
|
||||
if (options.onConnection)
|
||||
server.on("secureConnection", options.onConnection);
|
||||
} else {
|
||||
server = http.createServer(listener);
|
||||
if (onConnection != null) server.on("connection", onConnection);
|
||||
if (options.onConnection) server.on("connection", options.onConnection);
|
||||
}
|
||||
|
||||
if (keepAliveTimeout >= 0) server.keepAliveTimeout = keepAliveTimeout;
|
||||
server.listen(port, networkInterface);
|
||||
server.timeout = options.timeout || 0;
|
||||
if (options.keepAliveTimeout != null)
|
||||
server.keepAliveTimeout = options.keepAliveTimeout;
|
||||
server.listen({ port: options.port, host: options.host });
|
||||
}
|
||||
|
||||
export function stop(): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user